Repeater data set, but not showing

Hi all,

I have repeater on my website which I manually set, after fetching my collection data

 $w('#repeater1').data = []
$w('#repeater1').data = myData
$w('#repeater1').expand();

I set the data in the OnReady function:

$w("#repeater1").onItemReady(($item, itemData, index) => {

$item('#text1').text = itemData.myFirstField
$item('#text2').text = itemData.mySecondField;

})

My problem is that when navigating to this page with a direct link it will sometimes not show the collection data is set it to. It will never show the collection data when I use the browser back button.

If I set the data at a later moment than in the OnReady, for example with a ‘setTimeout’, it will show.

I have tried finding a method to track if the repeater has actually updated its view. But since the data is technically set, the following command logs the set amount of items, not the displayed amount.

 console.log( $w('#repeater1').data.length )

Does anyone know the correct way of tracking the amount of displayed items? Or even better an actual fix why the repeater doesn’t steadily show it’s items?

Best,
Jochem

Are you using a promise chain or await to ensure the data is retrieved once you set the repeater’s .data property? Otherwise you will run into issues where the variable you used to save the data (myData) is empty.

It may also be worth making sure the onItemReady() is being triggered when you set the .data property. You can do so by adding a console log message in the onItemReady().

A note in the .data property documentation states the following:

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.