Hi.
New to wix & javascript.
I have a query which returns the results I need, and I can set the result to the repeaters data property. However when I then hit the onItemReady() callback, the referenced item has reverted to the reference and not the nested array.
Here is the set up.
I have a collection called Student which contains a list of people (unique).
I have a second collection called Leaderboard with a “student” field that references the Student table.
This is the query
wixData
.query("Leaderboard")
.include("student")
.find()
.then((results) => {
if (results.items.length > 0) {
console.log(results.items);
let firstItem = results.items[0];
console.log(" NAME + " + firstItem.student.name);
$w('#repeater1').data = results.items;
console.log(" NAME + " + $w('#repeater1').data[0].student.name);
}
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
console.log("ERROR ** " + errorMsg);
});
The log of which is correct. As you can see below the results array contains all there referenced info in the nested array
0:
{…}
jsonTableCopy JSON
student:
{…}
jsonTableCopy JSON
name:
“John Doe”
_id:
“bca9c2aa-7f92-43c1-b71b-2745c44edd0d”
_owner:
“2d25bb8f-8a3e-4153-acad-4892bcd9e816”
_createdDate:
“Thu Jan 23 2025 11:48:59 GMT+0000 (Greenwich Mean Time)”
The console output shows
NAME + John Doe
NAME +John Doe
However, when onItemReady is called, the itemdata property now shows
{…}
jsonTableCopy JSON
student:
“bca9c2aa-7f92-43c1-b71b-2745c44edd0d”
So it appears that somehow it’s losing the array somewhere. Which makes no sense to me at all… is it a scope thing? anyone?