I am looking to populate a listView of events on the currently selectedDate of a calendar with data from an array(calendarListModel)
When a new date is selected from the calendar, I need the list to update, clearing and remaining empty if no events exist on the newly selected date, or replacing the listView with new delegates matching the newly selectedDate.
My array is created from a read from a firebase database, which works as intended. An example of my array would be;
calendarListModel: [
{"date":2019-02-12,"name":"user1"},
{"date":2019-02-13","name":"user1"},
{"date":2019-02-12,"name":"user2"}
]
If I set my model as calendarListModel My list shows every database entry regardless of date on the listView.
I have tried things such as;
model: calendarListView.date(calendar.selectedDate
also using loops to access the data, which i have had no success with, and most recently the following example;
function updateEvents() {
var eventModel = calendarListModel.find(
function(obj){
return obj.date === calendar.selectedDate.getDate(),
console.log(JSON.stringify(obj));
}
);
if (eventModel === undefined)
return eventListModel.length = [];
return eventListModel.push(eventModel)
}
Calendar {
id: calendar
selectedDate: new Date()
onSelectedDateChanged: {
const day = selectedDate.getDate();
const month = selectedDate.getMonth() + 1;
const year = selectedDate.getFullYear();
updateEvents()
}
}
ListView {
id:eventListView
model: eventListModel
}
My console log from the JSON.stringify(obj) seems to split my array into individual objects, with the logs showing:
{"date":1549972800000,"name":"user1"}
{"date":1550059200000,"name":"user1"}
{"date":1549972800000,"name":"user2"}
but when doing this eventListView and eventModel remain blank?
What can i do to correct this or what direction to i need to work in?