在使用Ember-Model排序之前,我的ArrayController与sortProperties和sortAscending按预期工作。最近我切换到了Ember-Model,排序功能不再适用了。
到目前为止代码:
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>
有什么想法吗?
THX