Why does this code not work?
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixData from 'wix-data'; // for query function
let ctnum; // declare a page variable
//TODO: write your page related code here...
$w.onReady(function () {
let Pctnum; // declare a function variable
Pctnum = 2; // set function variable to 0
wixData.query("NIaMem") // a collection that contain
// the ifno trying to display
.eq("Member", true ) // logic field in collection
.count() // count the logic colume
.then( (ctnum) => { // get results
Pctnum = ctnum; // set info into funtction var
$w("#text6").text = "what" + " " + Pctnum; //Display
})
.catch( (error) => {
let errorMsg = error.message;
console.log(errorMsg.items);
let code = error.code;
console.log(code.items);
});
$w("#text5").text = "why" + " " + Pctnum; //ctnum;
});
text5 gives me 2 and text6 gives me 0
Thanks,
Hi Ray.
Seems like the query returned 0 results.
The following row probably gets executed before you get results from wix-data request:
$w("#text5").text = "why" + " " + Pctnum; //ctnum;
since the request is made asynchronous (in the .then call)
Pay attention to the column name "Member" you are filtering on. You should use the Field Key property of a column (you can see it in the column properties in collection view) and not the Filed Name property.
Regards,
Genry.