I’ve been having a problem that is starting to annoy me. I can’t seem to use the result of a query outside of the query. With some small code I accepted it and continued some coding in the results, but that is just not acceptable for what I want to write now. So how can I use the value out of the query? I’ve tried all sort of things and googled everything I could thing of but sadly I didn’t find a solution.
An example below. After pressing a button I set a string in x. Then with the query I look for a value in my database and set that as x. The console.log in the query gives the expected result. The console.log out of the query still gives the random string as result. I’m not sure if it is a timing issue, a scope issue or something else but I can’t image there not being a way to make this work! If anyone knows how to do that please let me know.
export function buttontest_click(event) {
var x
x=“change me!”
wixData.query( “Database” )
.eq( “title” , “row 4” ))
.find()
.then( (results) => {
let items = results.items;
let item = items[ 0 ];
let column2= item.column2;
x=column2
console.log(x)
})
console.log(x)
}