[英]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示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.