Hi Gilbert ![]()
You need to return the query as well, it’s like the pyramid, you need to return everything from the top scoop to the end of the nested functions, example:
function getDetails() {
return wixData.query('class').find().then((x) => {
let class = x.items[0];
return wixData.query('students').eq('class', class.title).find().then((students) => {
let student = students.items[0];
return student.name;
})
})
}
Every find() function returns a Promise that resolves to the results found by the query and some information about the results, to return a value from the body of that function you need to return the value of the promise.
The student name value will be returned to the find() function as its value, so if you didn’t include a return word before the last find() function, the student name value will stuck there, and won’t be returned to the upper scoop.
To learn more about the promises, please visit this page.
Hope this helps~!
Ahmad