wix-data.WixDataQueryResult Query

wix-data.WixDataQueryResult
var query = wixData.query(“MyCollection”)
.eq(“ID”, “101”)
.find()
.then((results) => {
//console.log(results);
objReturn = results.items;
console.log(objReturn);
var items = results.items;
} );

  • If I am working with a data.WixDataQueryResult how am I able to pass “var item” out of the Query to use the information in the wider code, or does everything you want to do with with the result have to be done within the confines of the query?

Hi Andrew,

There are a few solutions here.

  • Create a function that will receive & handle the results data, then call the function in your .then.
  • Create a global variable to store the data. this allows you to read/write it from every section of your code
  • Use await before wixData. Then you can use the returned results after the wixData query promise returns.

Hi Ido, thank you for getting back to me!

  • If I create a function, would I use it simply to pass the array of results then assign them to a variable within the function?
  • In terms of a global variable, I had tried this (I think) by creating “var globalVar = null” at the top of the page rather than using “let” in the onReady, and I could not seem to get it to work?
  • I will look at await thanks.

Many Thanks for Engagin and helping
Andrew