在使用Ember-Model之前,使用sortProperties和sortAscending对ArrayController进行排序的工作符合预期。最近,我切换到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>
任何的想法?
谢谢
看起来对我有用,这是一个jsbin示例
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句