vendredi 23 octobre 2015

Ember: What is the non controller way to sort an array of models

I want to sort an array of Ember models by date but but it seems like all of the old documentation is related to sorting inside a controller. In this case I need to sort this array when I get the model in a route so I can send it to a service to have an action performed on it.

I have two models, site and flight.

so I have an object site whose constructor is is myApp@model:site

and I want to get an array of flight objects related to that site in a has many configuration sorted by date.

my attempt was:

var flights = site.get('flights').sortBy('executeAt:desc');

One weird thing I noticed is that without the ":desc" it defaults to ascending

var flights = site.get('flights').sortBy('executeAt'); -> ascending

But the value of what is after the colon doesn't affect anything

var flights = site.get('flights').sortBy('executeAt:'); -> descending or ``var flights = site.get('flights').sortBy('executeAt:asc');` -> descending

And in some case it messes up the sort entirely and gives me unsorted data.

For reference, date format is : 2015-09-03T13:34:33.000Z

So what is the best way to get a sorted list of this data?




Aucun commentaire:

Enregistrer un commentaire