i have a calendar for live bands on my site so i want something like
december
list of bands
january
list of bands
february
list of bands
so far i have this that queries my database for the listings for this month, next month and the next next month based on a new Date() function that is not posted:
// would love to loop this in a function - having trouble assigning results as a dynamic value
wixData.query("LiveMusic")
.ascending("dateId")
.ge ("dateId", today)
.eq("month", thismonth)
.find()
.then((results) => {
if(results.items.length > 0) {
liveMusic1 = results.items;
$w('#repeater1').data = liveMusic1;
}
})
})
.catch((err) => {
let errorMsg = err;
});
wixData.query("LiveMusic")
.ascending("dateId")
.eq("month", nextmonth)
.find()
.then((results2) => {
liveMusic2 = results2.items;
$w('#repeater2').data = liveMusic2;
if (liveMusic2.length < 1) { $w('#group66').collapse()} })
.catch((err) => {
let errorMsg = err;
});
wixData.query("LiveMusic")
.ascending("dateId")
.eq("month", twomonth)
.find()
.then((results3) => {
liveMusic3 = results3.items;
$w('#repeater3').data = liveMusic3;
if (liveMusic3.length < 1) { $w('#group67').collapse()}
})
.catch((err) => {
let errorMsg = err;
});
id really like to refactor this.
i tried this:
var queryItems = [
['thismonth', 'results', 'liveMusic1', '#repeater1'],
['nextmonth', 'results2', 'liveMusic2', '#repeater2'],
['twomonth', 'results3', 'liveMusic3', '#repeater3']
];
queryItems.forEach((query) => {
wixData.query("LiveMusic")
.ascending("dateId")
.ge ("dateId", today)
.eq("month", query[0])
.find()
.then((query[1]) => {
if(result.items.length > 0) {
query[2] = result.items;
$w(query[3]).data = query[2];
}
})
.catch((err) => {
let errorMsg = err;
});
})
but wix doesnt like assigning the .then(results) as a value and i think i need that or my query results are being overwritten. is it possible or is there an easier way to do this? maybe with a filter or a hook or something?