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

用户836968

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

任何的想法?

谢谢

劲派2k

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从arraycontroller排序子对象?

Ember.js:对ArrayController进行分组/分区

当ArrayController重新排序时,Ember itemController会重新实例化

在Eclipse中,如何对由Ivy解析的jar进行排序

如何仅使用Ember中的路线对模型进行排序?

Ember ArrayController中的互斥

如何使用Ember CLI在Ember中进行依赖项注入?

如何排序由私人领域的名单?

如何按字母顺序对由逗号分隔的字符串进行排序,并按成员的姓氏按字母顺序进行排序?

Ember.js ArrayController错误

如何根据条目由字母和数字组成的列对数据框进行排序?

如何对由该学说查询返回的实体对象数组进行排序?

如何对由因子组成的合并数据框和按字母顺序排序的x轴进行ggplot?

如何使用 BASH 对由特定字符分隔的行进行排序和 uniq

文本处理:如何按日期(由字符串分隔)对列表进行排序

当由客户端的下拉菜单触发时,如何对特定列进行排序?

如何获取由单独的列排序的DISTINCT ON子查询,并使其快速进行?

如何按列对由另一本词典组成的词典进行排序?

如何对由字符串数组组成的数组列表进行排序?

如何根据单个参数对由类实例组成的列表进行排序?

DRF:如何对由 SerializerMethodField 创建的自定义字段进行排序

按承诺对Ember对象数组进行排序

如何打印由FactoryGirl.create进行的Model.create调用?

如何对Rails Active Model序列化器的响应进行排序

如何在 Android 中手动对 ArrayList<Model> 进行排序?

如何对recyclerView进行排序

如何对散点图进行排序?

如何对ArrayList进行排序?

如何对选择进行排序