I am trying to concatenate data from a CMS to then display it in the text field of a repeater of a dynamic item page.
The datas are correctly loaded and concatenated, but only certain repeater items are correctly updated, the others keep the default text of the design.
Could you please help me, as I’ve been stuck on this for several days?
The part of code that does not work properly :
$w('#repeaterAwards').forEachItem(($item, data) => {
if (data._id === item._id) {
$item('#award').text = concatenatedData;
//console.log("\n",data,"\n",concatenatedData,"\n");
}
});
Full page code :
import wixData from 'wix-data';
// Utility function to show, expand, and mute/unmute a video
function showAndExpand(elementToShow, elementToHide, videoToPlay) {
elementToShow.expand();
videoToPlay.mute();
elementToHide.collapse();
}
$w.onReady(function () {
// Necessary initializations
$w('#boxAward').hide();
$w('#dataset2').onReady(() => {
// Handling the alternating display of videos
$w('#repeaterCompetences').onItemReady(($repeaterItem, repeaterItemData) => {
let even = repeaterItemData.order;
let videoPlayer = even % 2 === 0 ? $repeaterItem('#videoPlayer2') : $repeaterItem('#videoPlayer1');
// Start the video when the corresponding part is visible in the viewport
$repeaterItem('#v1').onViewportEnter(() => {
videoPlayer.play();
});
$repeaterItem('#v2').onViewportEnter(() => {
videoPlayer.play();
});
// Display and configure videos alternately
if (even % 2 === 0) {
showAndExpand($repeaterItem('#v2'), $repeaterItem('#v1'), $repeaterItem('#videoPlayer2'));
} else {
showAndExpand($repeaterItem('#v1'), $repeaterItem('#v2'), $repeaterItem('#videoPlayer1'));
}
});
// Loading data from the "Awards" collection
wixData.query("Awards")
.find()
.then(res => {
// After loading data, trigger the synchronized fade
let areImagesHidden = true;
const intervalBetweenImagesInMs = 500;
const fadeDurationInMs = 500;
$w('#repeaterAwards').onItemReady(($item, itemData, index) => {
$item('#boxAward').hide();
// Processing collection items
res.items.forEach(item => {
// Constructing the concatenated string with line breaks
let concatenatedData = `${item.award}\n${item.festival}`;
if (item.city) concatenatedData += `\n${item.city}`;
if (item.year) concatenatedData += ` ${item.year}`;
// Updating text in the repeater
$w('#repeaterAwards').forEachItem(($item, data) => {
if (data._id === item._id) {
$item('#award').text = concatenatedData;
//console.log("\n",data,"\n",concatenatedData,"\n");
}
});
});
// Start synchronized fade when the repeater is visible in the viewport
$w('#repeaterAwards').onViewportEnter(() => {
if (areImagesHidden) {
$w('#repeaterAwards').forEachItem(($item, itemData, index) => {
setTimeout(() => {
$item('#boxAward').show('flip', { duration: fadeDurationInMs });
$item('#boxAward').show('fade', { duration: fadeDurationInMs });
}, intervalBetweenImagesInMs * index);
});
areImagesHidden = false;
}
});
});
})
.catch(err => {
console.error(err);
});
});
// Handling page scrolling
$w('#piedPage').onViewportEnter(() => {
$w('#scrollDownIndicator').hide('fade', { duration: 300 });
});
$w('#piedPage').onViewportLeave(() => {
$w('#scrollDownIndicator').show('fade', { duration: 300 });
});
});