Javascript 如何对由Ember模型支持的ArrayController进行排序?

Javascript 如何对由Ember模型支持的ArrayController进行排序?,javascript,ember.js,ember-model,Javascript,Ember.js,Ember Model,在使用Ember模型之前,使用sortProperties和sortAscending对ArrayController进行排序,结果与预期的一样。最近我切换到余烬模型,排序功能不再工作 迄今为止的代码: App.Movie = Ember.Model.extend({ rating: Ember.attr(), title: Ember.attr(), watched: Ember.attr(), year: Ember.attr(), }); App.MoviesIndexC

在使用Ember模型之前,使用sortProperties和sortAscending对ArrayController进行排序,结果与预期的一样。最近我切换到余烬模型,排序功能不再工作

迄今为止的代码:

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>
App.Movie=Ember.Model.extend({
评级:Ember.attr(),
标题:Ember.attr(),
已监视:Ember.attr(),
年份:Ember.attr(),
});
App.MoviesIndexController=Ember.ArrayController.extend({
sortProperties:null,
排序设置:空,
行动:{
sortByAttribute:函数(属性){
if(this.get('sortProperties')){
if(this.get('sortProperties')[0]==attr){
此.toggleProperty('sortAscending');
}否则{
this.set('sortProperties',[attr]);
}
}否则{
this.set('sortProperties',[attr]);
此.set('sortAscending',true);
}
}
}
});
年
...
有什么想法吗


Thx

对我来说似乎很有效,下面是一个jsbin示例


我觉得它很管用,下面是一个jsbin示例

这对我有用:这对我有用: