It looks like it works to me, here's a jsbin example
How to sort an ArrayController backed by Ember-Model?
-
04-08-2022 - |
Question
Prior to using Ember-Model sorting my ArrayController with sortProperties and sortAscending worked as expected. Lately I switched to Ember-Model and the sorting feature doesn't work anymore.
Code so far:
App.Movie = Ember.Model.extend({
rating: Ember.attr(),
title: Ember.attr(),
watched: Ember.attr(),
year: Ember.attr(),
});
App.MoviesIndexController = Ember.ArrayController.extend({
sortProperties: null,
sortAscending: null,
actions: {
sortByAttribute: function (attr) {
if (this.get('sortProperties')) {
if (this.get('sortProperties')[0] === attr) {
this.toggleProperty('sortAscending');
} else {
this.set('sortProperties', [attr]);
}
} else {
this.set('sortProperties', [attr]);
this.set('sortAscending', true);
}
}
}
});
<table>
<thead>
<tr>
<th {{action "sortByAttribute" "year"}}>Year </th>
</tr>
</thead>
...
</table>
Any idea?
Thx
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow