Hi does anyone from wix team or code expert help me or at least tell whats wrong with my code. Shortly there is function getEmptyrooms that compares two queries and gives me not used items. It works because gives me results in console.log than i want to put results to dropdown with field “imie” from array because i want only not used records there to choose from dropdown.
$w.onReady( function () {
uniqueDropDown1();
})
function uniqueDropDown1 (){
getEmptyRooms()
.then(results => {
let options = [{“value”: ‘’, “label”: ‘All Continents’}];
options.push(…results.items.map(continent => {
return {“_id”: continent.imie, “label”: continent.imie};
}));
$w(‘#dropdown2’).options = options;
// let items = results.items
// let titlesOnly = items.map(item => item.imie);
// console.log(results);
//console.log (“rrrrrrrrrrrrrrrrrrrrrrrrrrrrrr”);
// let uniqueTitles = getUniqueTitles(results.items);
// $w(“#dropdown2”).options = buildOptions(uniqueTitles);
//console.log(uniqueTitles)
//console.log (“rrrrrrrrrrrrrrrrrrrrrrrrrrrrrr”)
});
function getEmptyRooms() {
// Get list of occupied rooms (we return a Promise so that the calling function can
// process the results
return getOccupiedRooms()
.then((occupiedRoomList) => {
let emptyRoomQuery = wixData.query(“listagosci”);
// loop through occupied rooms creating a list of queries to exclude occupied rooms
for ( let i = 0 ; i < occupiedRoomList.length; i++) {
// Get a record to exclude
let occupiedRoomRecord = occupiedRoomList[i];
let exclusionQuery = wixData.query(“listagosci”)
.eq(“_id”, occupiedRoomRecord.gosc);
emptyRoomQuery = emptyRoomQuery.not(exclusionQuery);
}
// We have built our Empty Room Query - now execute it
return emptyRoomQuery
// .ascending(“sortowanie”)
.find();
})
.then((results) => {
console.log("ooooooooooooooooooooooooooooooooooooooooooo")
console.log(results)
return Promise.resolve(results.items);
});
}
let user = wixUsers.currentUser;
let userId = user.id;
function getOccupiedRooms() {
return wixData.query(“stoly”)
.eq(“_owner”, userId)
.isNotEmpty(“_owner”)
.isNotEmpty(“gosc”)
.find()
.then((result) => {
console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")
console.log(result)
// Return a promise with the array of occupied rooms
return Promise.resolve(result.items);
} )
}