Case: Using the repeater’s onItemReady function to set image’s src inside the repeater’s containers.
When I created the onItemReady function from the properties panel 20-30% of the containers inside the repeater failed to set their image’s src (code below)
export function repeater1_itemReady($item, itemData, index) {
$item("#btn").link = `https://www.google.org`;
$item("#image").link = `https://www.google.org`;
let words = itemData.excerpt;
var myTruncatedString = words.substring(0, 105);
$item("#image").src = itemData.baseImage; //problem
$item("#listTitle").text = itemData.farmName;
$item("#desc").text = myTruncatedString + '...';
}
But when I deleted the function from the properties panel and manually wrote the following code, I’m having a 100% success rate.
$w.onReady(function () {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
$item("#btn").link = `https://www.google.org`;
$item("#image").link = `https://www.google.org`;
let words = itemData.excerpt;
var myTruncatedString = words.substring(0, 105);
$item("#image").src = itemData.baseImage;
$item("#listTitle").text = itemData.farmName;
$item("#desc").text = myTruncatedString + '...';
});
});
This is not the first time I noticed this. A couple of months ago (in November 2019) same happened with the dynamicDataset’s onReady function. When I deleted the function from the properties panel and added it under the page’s onReady function it was perfect.
Should we be using the page’s onReady function over the functions created using the properties panel in these cases?