繁体   English   中英

如何对由Ember-Model支持的ArrayController进行排序?

[英]How to sort an ArrayController backed by Ember-Model?

在使用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>

任何想法?

谢谢

看起来对我有用,这是一个jsbin示例

http://emberjs.jsbin.com/eKibapI/8/edit

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM