Code for dropdown list with not used items

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);

      }    ) 

}

Hi,

At the uniqueDropDown1() function the promise that return from the getEmptyRooms() function, is results.items (means an array of objects that each object is an item).
As a result, unless you have an items
field in the database “listagosci” the map should be only on the results you got from the promise.

If there is still a problem, please send us a pictures of your databases and also specified exactly when the problem is accord in your code.

Best of luck!
Sapir,

2 days and almsot 2 night i was looking for solustion :slight_smile: and it was only one word :)))))) Works. Thanks