Ember.js:使用@each观察数组属性不起作用 [英] Ember.js: Observing array property using @each doesn't work
问题描述
我的理解是观察'@each'意味着我正在观察数组中的任何属性的任何更改,但似乎不起作用。例如:
My understanding is that observing for '@each' means that I'm observing any change to any property in an array, but it doesn't seem to work. For example:
App.ArrayProxy = Ember.ArrayProxy.extend({
i: 0,
foo: function(){
console.log('foo called');
return ++this.i;
}.property('content.@each')
});
我也尝试过.property('@ each'),而不是.property('content。 @each')同样令人失望的结果。
I've also tried .property('@each') instead of .property('content.@each') with equally disappointing results.
这是一个jsbin,演示: http://jsbin.com/hagar/5/edit
Here is a jsbin that demonstrates: http://jsbin.com/hagar/5/edit
在演示中,更改数组列表本身(通过点击删除最后按钮)触发刷新foo计算属性,但更改数组中对象的属性不会。
In the demo, changing the array list itself (by clicking the 'Remove Last' button) triggers a refresh of the 'foo' computed property, but changing a property of an object in the array doesn't.
这个问题?
推荐答案
您需要使用setter(或内置的 incrementProperty
),如果您关心名称更改,我添加了名称。
You need to use a setter (or the built in incrementProperty
), I added name if you care when the name was changed.
foo: function(){
console.log('foo called');
return this.incrementProperty('i');
}.property('content.@each.name')
foo: function(){
console.log('foo called');
return this.incrementProperty('i');
}.property('content.[]')
http://jsbin.com/bakoqawi/1/edit
这篇关于Ember.js:使用@each观察数组属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!