Hello,
I was hoping someone could help me out with an issue I’m having. I have two collections set up:
events
{eventName, eventId, hostVenue, eventDate}
and
bookingsConfirmed
{eventId, artistId, setTime}
They are connected by reference; eventId from bookingsConfirmed references eventId from events. On my page I have a repeater to display an artist’s upcoming events. I have the following code added on the page:
//repeater
$w("#upcomingGigsRep").onItemReady( ($item, itemData, index) => {
$item("#upcomingEventName").text = itemData.eventId.eventName;
$item("#upcomingVenueName").text = itemData.eventId.hostVenue;
$item("#upcomingDay").text = itemData.eventId.eventDate.toLocaleDateString("en-US", {weekday: "long"});
$item("#upcomingDate").text = itemData.eventId.eventDate.toLocaleDateString("en-US", {day: "numeric", month: "short"});
});
wixData.query("BookingsConfirmed")
.include("eventId")
.eq('artistId', wixUsers.currentUser.id)
//.ascending("eventId.eventDate") // need something like this
.find()
.then( (results) => {
console.log(results.items);
// add query results to repeater
$w("#upcomingGigsRep").data = results.items;
});
At the moment everything works fine except I can’t figure out how to display the events in order of their date. the query returns the following block:
{ artistId: "d3b94669-914f-4ae8-a132-7aeaa0fa47ac",
eventId:
{ eventDate: Sat Jul 06 2019 00:00:00,
eventId: "12349",
eventName: "Josh's Party",
hostVenue: "Josh's Place",
title: "12349",
_createdDate: Fri Jul 05 2019 17:37:08,
_id: "75a4f5c9-7634-4402-a784-6ae2de9c700e",
_owner: "32dc03df-eca0-4d3c-84d7-4480fd08ee40"
_updatedDate: Fri Jul 05 2019 18:01:13,
__proto__: Object
},
setTime: "8:30"
}
I have simplified the above block a bit for easier readability, but the theory is the same. I am trying to sort by eventDate so I would need to access that through eventId, something like
sort().ascending("eventId.eventDate")
but I can’t figure out the syntax.
Any suggestions?
Thanks.