通过计算机属性将新记录添加到商店时进行收听 [英] Listening when new records are added to the store via a computer property
问题描述
我通过手柄模板在屏幕上显示项目
{{项目中的每个项目}}
< div> {{item.name}}< / div>
{{/ each}}
在我的控制器中,我收集了
items:function(){
var items = this.store.find('items');
return items.filterBy({type:NEW});
} .property()
现在,当新的记录添加到商店时,我需要自动更新项目。
items:function(){
var items = this.store.find '项目');
return items.filterBy({type:NEW});
} .property('??????')
那么有一些通过计算属性添加记录时侦听存储的方式。理想情况下,我想听一个特定类型的模型。
最好的方法是做: p>
items:function(){
return this.store.filter(function(item){
return item .get('TYPE')==='NEW';
});
} .property()
store.filter
返回一个活动数组,只要存储中有任何更改,就会更新,因此它将响应推送的新记录。
I am pushing records into my store using websockets.
I am displaying items on the screen via a handlebars template
{{#each item in items}}
<div>{{item.name}}</div>
{{/each}}
In my controller I have the items collection
items : function() {
var items = this.store.find('items');
return items.filterBy({type : "NEW"});
}.property()
Now, when new records are added to the store, I need to update the items automatically.
items : function() {
var items = this.store.find('items');
return items.filterBy({type : "NEW"});
}.property('??????')
So is there some way of listening to the store when records are added via a computed property. Ideally I would like to listen to models of a particular type.
The best way to do this is to do:
items : function() {
return this.store.filter(function(item){
return item.get('TYPE') === 'NEW';
});
}.property()
store.filter
returns a live array that updates whenever there are any changes in the store, so it will respond to the new records beings pushed.
这篇关于通过计算机属性将新记录添加到商店时进行收听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!