I don’t understand how is that the output for this code is:
final filter is:
coreNameFound:
if in my code the first output is “coreNameFound” and only then “final filter is”.
May be query method is async? So what is the “wait” method?
Please help!!!
export function buildFilter () {
// $w(“#datasetFields”).onReady( () => {
var filter = wixData.filter();
var coreName = “”;
//filter by fields category
filter = filter.eq('fieldCategory', $w('#dropdownFieldCategory').value);
wixData.query('SK4CoreEvents')
.eq('_id', $w("#dynamicDataset").getCurrentItem("coreEvent").coreEvent)
.find()
.then(results => {
let items = results.items;
let item = items[0];
coreName = item[“coreEventName”];
console.log(“coreNameFound:”+coreName);
});
if (coreName.length>0)
{
console.log(“add to filter:”+coreName);
filter = filter.eq(‘coreEvent’, coreName);
}
console.log(“final filter is:”);
console.log(filter);
//finally, set the filter
$w(“#datasetFields”).setFilter(filter);
//});
}