Ember.ArrayProxy更改不触发句柄#each更新 [英] Ember.ArrayProxy changes not triggering handlebars #each update
问题描述
我正在覆盖内容属性来更新数组。数组不会更新,但视图不会更新。
App.items = Ember.ArrayProxy.create({
content:[
Ember.Object。创建({name:'Me',city:'new york'}),
Ember.Object.create({name:'你',city:'boston'})
],
sortByCity:function(){
this.set('content',this.get('content')。sort(function(a,b){
return a.get ('city')> b.get('city')
}));
}
});
这是一个演示问题的小提琴 http://jsfiddle.net/alexrothenberg/za4Ha/1/
任何帮助不胜感激。谢谢!
修正: http://jsfiddle.net/MikeAski/za4Ha/2/ (我通过引入一个 CollectionView
来重构你的代码
您应该使用 replaceContent
原语替换 ArrayProxy
内容并保持绑定绑定...
I suspect there is a way to update an Ember.Array proxy that will trigger ember's notifications but what I can't figure out how.
I am overwriting the "content" property to update the array. The array does update but the view does not.
App.items = Ember.ArrayProxy.create({
content: [
Ember.Object.create({ name: 'Me', city: 'new york'}),
Ember.Object.create({ name: 'You', city: 'boston'})
],
sortByCity: function() {
this.set('content', this.get('content').sort(function(a,b) {
return a.get('city') > b.get('city')
}));
}
});
Here's a fiddle that demonstrates the problem http://jsfiddle.net/alexrothenberg/za4Ha/1/
Any help is appreciated. Thanks!
Fixed it: http://jsfiddle.net/MikeAski/za4Ha/2/ (I refactored your code a little, by introducing a CollectionView
to render the items).
You should use replaceContent
primitive to replace an ArrayProxy
content and keep the bindings bound...
这篇关于Ember.ArrayProxy更改不触发句柄#each更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!