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;
}
})
}
})
});
@sapirh thank you for the detailed response and code, very much appreciated! I have tried to implement but there is still only the price and duration that fill in and only one container will populate.
import wixData from 'wix-data';
$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("#price").text = itemData.individaulPrice;
$item("#duration").text = itemData.duration;
}
Again, thank you for your help, my skills have come a long way with help in this community but this is stumping me! I can obviously get the date to populate if I just use one fieldKey i.e.
$item('#date').text = date1;
But it confusing me as the 3 date fields are in the same Item
In the onItemReady() function you need to write all the items that inside the repeater besides the ‘duration’ and ‘price’ that are calculated separately.