Ember.ArrayProxy更改不触发句柄#each更新 [英] Ember.ArrayProxy changes not triggering handlebars #each update

查看:102
本文介绍了Ember.ArrayProxy更改不触发句柄#each更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑有一种方法可以更新Ember.Array代理,这将会触发ember的通知,但是我无法弄明白如何。



我正在覆盖内容属性来更新数组。数组不会更新,但视图不会更新。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆