我有結構是這樣的模式:即使我沒有指定它的依賴關係,爲什麼計算的屬性被更新?
App = {};
App.Outer = Ember.Object.extend({
inner: null,
quantity: 0,
count: function() {
var self = this, inner = self.get('inner');
return self.get('quantity') * inner.get('count');
}.property('nothing')
});
App.Inner = Ember.Object.extend({
count: 0
});
是,「計數」計算性能真的被設置爲依賴於一個完全不存在的屬性「無」。但它似乎無論如何得到更新:
var o1 = App.Outer.create({
quantity: 2,
inner: App.Inner.create({count: 4})
});
console.log(o1.get('count')); // => 8
o1.get('inner').set('count', 5);
console.log(o1.get('count')); // => 10
o1.set('inner', App.Inner.create({count: 10}));
console.log(o1.get('count')); // => 20
我錯過了什麼嗎?它知道如果沒有我告訴它要依靠什麼更新......不對,可以嗎?我對Ember計算屬性有什麼誤解?
感謝
注意,'.property( '無')'相當於這裏'.property()'---可能簡化這個問題。 – 2012-02-10 14:04:50