[英]How to sort an ArrayController backed by Ember-Model?
Prior to using Ember-Model sorting my ArrayController with sortProperties and sortAscending worked as expected. 在使用Ember-Model之前,将我的ArrayController与sortProperties和sortAscending进行排序的工作符合预期。 Lately I switched to Ember-Model and the sorting feature doesn't work anymore.
最近,我切换到Ember-Model,并且排序功能不再起作用。
Code so far: 到目前为止的代码:
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>
Any idea? 任何想法?
Thx 谢谢
It looks like it works to me, here's a jsbin example 看起来对我有用,这是一个jsbin示例
http://emberjs.jsbin.com/eKibapI/8/edit http://emberjs.jsbin.com/eKibapI/8/edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.