首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对由Ember支持的ArrayController进行排序?

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

Stack Overflow用户
提问于 2013-11-23 13:31:56
回答 1查看 272关注 0票数 1

在使用Ember模型之前,将我的ArrayController与sortProperties和sortAscending进行排序就像预期的一样。最近我转向了Ember-Model,排序功能不再起作用了。

目前为止的代码:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-23 15:17:37

在我看来,这是可行的,下面是一个jsbin示例

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20162930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档