Hi team,
I'm trying to display 3 dates from the same entry in a database but seem to be getting stuck, below os the code and it all works until I try to display any more than one date. To clarify I want three containers with all the same info apart from the dates, which would be different.
$w.onReady(function () {
wixData.query('Courses')
.eq('title', 'Aonach Eagach Guided Traverse')
.find()
.then((results) => {
if (results.totalCount > 0) {
$w('#repeater2').data = results.items;
$w('#repeater2').forEachItem(($item, itemData, index) => {
for (let i = 1; i <= 3; i++) {
let date1 = itemData.dateone.toLocaleString();
let date2 = itemData.dateTwo.toLocaleString();
let date3 = itemData.datethree.toLocaleString();
$item('#price').text = '£' + itemData.individaulPrice;
$item('#duration').text = itemData.duration;
$item(`date${i}`).text = date1, date2, date3;
}
})
}
})
});
Would anyone be able to help?
Thank you!
Hi,
In the onItemReady() function you need to write all the items that inside the repeater besides the 'duration' and 'price' that are calculated separately.
Best,
Sapir
Hi,
I believe your problem is that you didn't connect the repeater's elements to their data.
Using '$w('#repeater2').data = results.items' means that you didn't connect the repeater's items directly to a dataset according to this article:
https://support.wix.com/en/article/about-displaying-database-content-in-a-repeater
As a result, it has to be done by code. Add an onItemReady() function that runs when a new repeated item is created, view the API for more information https://www.wix.com/corvid/reference/$w.Repeater.html#onItemReady and determine the contact of each element.
View this code and implement it in your site:
$w.onReady(function () { setDates(); }) async function setDates() { let results = await wixData.query('Courses').eq('title', 'Aonach Eagach Guided Traverse').find(); if (results.totalCount > 0) { //This will triggered the onItemReady() function $w('#repeater2').data = results.items; $w('#repeater2').forEachItem(($item, itemData, index) => { for (let i = 1; i <= 3; i++) { let date1 = itemData.dateone.toLocaleString(); let date2 = itemData.dateTwo.toLocaleString(); let date3 = itemData.datethree.toLocaleString(); $item('#price').text = '£' + itemData.individaulPrice; $item('#duration').text = itemData.duration; $item(`date${i}`).text = date1, date2, date3; } }) } } export function repeater2_itemReady($item, itemData, index) { $item(".....") = itemData. }
Best of luck!
Sapir