【发布时间】:2014-05-04 11:34:09
【问题描述】:
我正在尝试根据来自文本输入的输入使用Ember.computed.filter 过滤 ArrayController 的内容。
App.IndexController = Ember.ArrayController.extend({
filteredPeople: Ember.computed.filter('model', function(person){
var searchFilter = this.get('searchFilter');
var regex = new RegExp(searchFilter, 'i');
return person.firstName.match(regex);
}),
// this is bound to the value of a text input helper
// I'm just pre-filling the value to show that the filtering does work
searchFilter: 'kris'
});
这很好用并且可以按预期过滤。但是,我希望它在 searchFilter 的值发生更改时更新(即,任何时候有人输入文本输入)。现在的问题是,它仅在模型本身发生更改或控制器首次加载时才会更新。
当searchFilter 更新时,是否有触发Ember.computed.filter 更新?我正在使用Ember.computed.filter,因为它似乎比普通的计算属性更有效,我相信每次都会重新创建整个数组(如果我弄错了,请告诉我)。此外,Ember.compute.filter 简单易用且非常干净!
我使用上述设置创建了一个 JSBin。当用户输入文本框时,我想以某种方式触发Ember.computed.filter 进行自我更新。
感谢您的时间和任何帮助。
【问题讨论】:
标签: ember.js