Hi everyone!
I’m learning ember (v3.15) and I’ve been batling with an issue for the last couple of days that I can’t solve . My problem is sorting a list of ember data records inside a component.
I’m trying to build a calendar component (a simple table) that displays my vacations for the entire year. To do this, I use ember-data to retrieve the list of dates (each record has a startDate and endDate) with my vacations in the routes model():
The list of dates is passed to the component like so (the argument is @vacationsList):
<Vacations::VacationsEditor @count={{this.model.count}} @vacationsList={{@model.dates}} @addNewVacationDate={{this.addNewVacationDate}} @updateCounter={{this.updateCount}} />
So far so go. I can display the list inside my component using {{@vacationsList}}.
The issue comes when I try to modify the records list. To generate the table, I need to sort the records by the startDate property (among other things) and I can’t find a way to do this that works.
I created a computed property to iterate over the records and return something that the component can use but the console.log() statement is never executed. I assume this is because I’m working with a promise?
@computed
get months(){
this.args.vacationsList.forEach(x => {console.log(x);});
let months = [];
return months;
}
Another thing I’ve tried was using the @sort() computed property in the routes controller. This works in the sense that it sorts the list but once I’m inside the computed property I can’t iterate the this.args.vacationsList array (@sort() returns a MutableArray if I’m not mistaken) because it’s always empty.
What am I doing wrong?