I have a code that supposed to display some text and image from a query result. The repeater is populated with the query results, and I can see in the console. Text elements are displayed properly, however, for some reason, instead of the query result images, only the repeater’s first placeholder image is shown for each query image. Which part of the code causes this?
In the editor:
In he preview mode:
and here is the code:
import wixData from "wix-data";
let currentPageN
$w.onReady(function () {
$w("#pagination1").onChange((event) => {
currentPageN = event.target.currentPage;
selectingItemToDisplay();
})
});
export function searchBox_keyPress(event) {
if (event.key === "Enter") {
queryDS();
}
}
let itemPerPageN = 4;
let repeaterData;
function queryDS() {
wixData.query("MultiItem_1")
.contains("text", $w('#searchBox').value)
.find()
.then((results) => {
$w("#repeater1").data = results.items;
repeaterData = results.items;
let totalPageN = repeaterData.length / itemPerPageN
if (!Number.isInteger(totalPageN)) {
totalPageN = Math.ceil(totalPageN);
}
$w('#pagination1').currentPage = 1;
currentPageN = 1;
$w('#pagination1').totalPages = totalPageN;
selectingItemToDisplay();
});
}
function selectingItemToDisplay() {
let firstItemIndex = (currentPageN - 1) * itemPerPageN;
let lastItemIndex = firstItemIndex + itemPerPageN;
let slicedRepeaterData = repeaterData.slice(firstItemIndex, lastItemIndex);
$w("#repeater1").data = slicedRepeaterData;
settingRepeater()
}
function settingRepeater() {
$w('#repeater1').onItemReady(($item, itemData, index) => {
$item('#text1').text = itemData.text;
$item('#image1').image = itemData.image;
console.log(itemData.image)
switch (itemData.type) {
case 1:
$item("#text1").expand();
$item("#image1").collapse();
break;
case 2:
$item("#text1").collapse();
$item("#image1").expand();
break;
}
});
$w('#repeater1').expand();
$w('#pagination1').expand();
}
Thanks