I have several repeaters set to load in a function called from the on.Ready function.
Each repeater was pre-loaded with ONE default item from the editor.
I query the DB and get some data, then loop to incrementally populate this into the repeaters.
Upon execution the following occurs in this order (on my page and Developers Console)
1) The NEW correct data is briefly displayed in the repeater
2) The console.log statement in the myRepeaterLoadFunction does not display
(understandable if the "backend" code rendering cycle is what is running)
3) Then AFTER the "finished hydrate" message displays in the Developers Console (which I assume signals that the "backend" code has finished), the console.log statement prints correctly with all of my new data for each repeater from the for loop calls.
4) However, the repeater display immediately reverts back to the single default data record that was loaded from the editor as soon as the code finishes executing (after the last console.log statement is written.)
Seems like a rendering issue to me. It is like the "backend" code rendering works properly, but then the "browser" rendering cycle is resetting something.
I have tried wrapping the query (as well as the for statement) in
if (wixWindow.rendering.renderCycle === 1) {....} if (wixWindow.rendering.env === "backend") {....}
using various combinations of renderCycle= (1,"1",2,"2") and env=("backend" and "browser").
It seems logical that this could be the issue, but nothing fixes this, I am stumped.
Anyone have any suggestions?
Any help would be most appreciated....
$w.onReady(async function () {
let myItems = await getSomeData(); // contains repeater names and variables
for (var i = 0, len = myItems.length; i < len; i++) {
let status = await myRepeaterLoadFunction(myItems[i]);
console.log("Status= " + status)
}
});
async function myRepeaterLoadFunction(myItem) {
let newIdNum = await getIdNum(); //function to get random id num - starts with "PBP"
// Build New Repeater data element for insertion
const tempRptrData = [{
"_id" : newIdNum,
"image" : myItem.inputSrc,
"displayValue" : myItem.inputDesc
}];
$w("#" + myItem.repeaterName).onItemReady(($item, itemData, index) => {
$item("#" + myItem.sourceVarName).src = itemData.image;
$item("#" + myItem.descVarName).text = itemData.displayValue;
});
let tempData = $w("#" + myItem.repeaterName).data;
if (tempData[0]._id.substring(0, 3) !== "PBP") { tempData.splice(0, 1) } // delete 1st record
$w("#" + myItem.repeaterName).data = tempData.concat(tempRptrData);
console.log("MyRptrData = ",$w("#" + myItem.repeaterName).data); // displays correct data!
return "success";
}