gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 01:46:56 25 4
gpt4 key购买 nike

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

关于javascript - 如何对 Ember-Model 支持的 ArrayController 进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20162930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com