如何观察Ember数据存储中的更改? [英] How to observe for changes in the Ember data store?
问题描述
我有一些Fixture数据,其中的每个项目都有一个名为isFavourite的布尔属性。 indexRoute
只显示所有可用数据以及显示收藏项的第二部分。每个项目也有一个类绑定到这个 isFavourite
属性。如果它是最喜欢的,它将会有红色文本。
有一个第二个路线叫做 dashboard
来自商店的数据的子集。还有一个按钮来切换最喜欢的属性。当这被切换时,更改反映在索引路由上的类绑定中,但是 c>收藏夹部分,只是一个中继器仍然显示旧数据。
如何为中继器建立绑定,以便项目根据 isFavourite
属性
尝试这样:
App.IndexController = Ember.Controller.extend({
favorites:function(){
return this.store.filter('documenter',function(x){
^^^^^
return x.get('isFavourite');
});
} .property('model')
} )
这样做的原因是 this.store.filter
返回一个随着事情变化而更新的live集合。
在JSBIN上为我工作。
I created this simple JsBin to demonstrate what I'm after.
I have some Fixture data and each item in it has a boolean property called isFavourite. The indexRoute
just displays all the available data along with a second section that displays the items that are favourites. Each item also has a class binding to this isFavourite
property. If it's a favourite, it'll have red text.
There is a second route called dashboard
which only displays a subset of the data from the store. There is also a button to toggle the favourite property. When this is toggled, the change is reflected in the class binding on the index route but the Favourites
section, which is just a repeater still shows the old data.
How do I establish a binding for the repeater so that the items change according to the isFavourite
property?
Try this:
App.IndexController = Ember.Controller.extend({
favourites: function() {
return this.store.filter('documenter', function(x) {
^^^^^^^^^^^^^^^^^
return x.get('isFavourite');
});
}.property('model')
})
The reason this works is that this.store.filter
returns a "live" collection that is updated as things change.
Works for me on your JSBIN.
这篇关于如何观察Ember数据存储中的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!