Hello,
I have this code
$w.onReady(function () {
let $repeater = $w('#repeater2');
$repeater.onItemReady(($item,itemData,index) => {
console.log('onitemready fired for ',itemData.name);
});
$repeater.data =
[
{ name : 'Apple' , price : 50 , _id : 'item1' } ,
{ name : 'Orange' , price : 30 , _id : 'item2'},
{ name : 'Bannana' , price : 22 , _id : 'item3'}
];
});
The wix documentation at data - Velo API Reference - Wix.com - states that onItemReady() has to be placed before Repeater.data.
“Because setting a repeater’s data property triggers the onItemReady() callback to run, make sure you call onItemReady() before you set the data property. Failing to do so will mean that your callbacks are not triggered when you set the data property.”
Firstly, it seems to work regardless of where I place it. Is this wrong?
Secondly, I noticed when the above code is tested the onItemReady() doesn’t trigger for Apple, but triggers for the other two.
UPDATE :
It has something to do the the _id of the first item. For some reason using ‘item1’ as the _id won’t trigger onItemReady() but changing it to ‘myItem1’ causes onItemReady() to fire correctly on apple.
onItemReady() triggers for all 3 items :
let repeaterData =
[
{ name : 'Apple' , price : 50 , _id : 'myItem1' } ,
{ name : 'Orange' , price : 30 , _id : 'item2' },
{ name : 'Bannana' , price : 22 , _id : 'item3' }
];
onItemReady() triggers for all items 2 and 3 only :
let repeaterData =
[
{ name : 'Apple' , price : 50 , _id : 'item1' } ,
{ name : 'Orange' , price : 30 , _id : 'item2' },
{ name : 'Bannana' , price : 22 , _id : 'item3' }
];