【发布时间】:2012-04-12 04:20:03
【问题描述】:
我有一个 individualStore(从 Em.ArrayController 扩展),它的任务是保存一个单独的对象数组。我的应用程序调用了几个 API,它们返回发送到商店的各个对象。将其视为我的应用程序中缓存的单个记录的数据库。
App.individualStore = App.ArrayController.create({
allIndividuals: function () {
return this.get('content').sort(function (a, b) {
return (b.votes_count - a.votes_count);
});
}.property('@each.votes_count').cacheable(),
aliveIndividuals: function () {
return this.get('content').filter(function (individual) {
return (!!individual.living);
}).sort(function (a, b) {
return (b.votes_count - a.votes_count);
});
}.property('@each.living', '@each.votes_count').cacheable(),
deceasedIndividuals: function () {
return this.get('content').filter(function (individual) {
return (!individual.living);
}).sort(function (a, b) {
return (b.votes_count - a.votes_count);
});
}.property('@each.living', '@each.votes_count').cacheable()
});
我的视图有一个 `individualsBinding: 'App.individualStore.allIndividuals',它按预期完美呈现。
我想添加过滤按钮,例如Show: All | Alive | Deceased。在这里更改过滤的正确方法是什么?请记住,无论标准是什么,我都希望它始终与 individualStore 保持同步。
有人建议在运行时更改绑定,
this.bind('users', Ember.Binding.from('App.individualStore.aliveIndividuals'));
这在我前两三次单击这些按钮时有效,但随后它冻结了浏览器(有点像无限循环?)。
这对我来说也不是最好的选择。我是 ember 的新手,所以你说的任何内容都会有所帮助。提前致谢。
【问题讨论】: