I use a model in Ember.js like this:
App.SomethingRoute = Ember.Route.extend({
model: function()
{
return App.MyData.find();
}
});
It receives data from MyData. In my data i have a field called "NAME". I would like to display data from MyData in ascendant order by NAME.
I've added a controller (thx. Toran, intuitive) like this:
App.SomethingController = Ember.ArrayController.extend({
sortProperties: ['NAME'],
sortAscending: true
});
But my template that is like this:
{{#each model}}
{{NAME}}
{{/each}}
Still shows unordered list. How to make it right?
Make sure you are using {{#each controller}}, not {{#each model}}, since the Controller will have it own copy of the model collection that it sorts and presents to the template.
Since the
ArrayController
includes theSortableMixin
(already mentioned in the comment from @ianpetzer), you can set the properties you want to sort on insortProperties
.ArrayController
has been removed from Ember (v2.0) since this question was asked. Here is how you would achieve the same without using anArrayController
:And then:
And here is the documentation for Ember's computed
sort
macro.Make sure your find method does something like this
Not this (this will not update the template via binding because it's a vanilla JS object instead of a full blown ember object)