0
我正在嘗試使用計算屬性,該屬性觀察數組中每個元素的特定屬性的更改。這是小提琴。點擊更改按鈕,並且計算的屬性不會觸發。爲什麼?爲什麼不是這個爲@each計算的屬性射擊?
這裏是小提琴: http://jsfiddle.net/inconduit/PkT8x/145/
和這裏的相關代碼
App.color1 = Ember.Object.create({ color : "red"});
// a contrived object that holds an array of color objects
App.colorsHolder = Ember.Object.create({
colors : Ember.A([App.color1]),
});
App.ApplicationController = Ember.Controller.extend({
colorsHolder : App.colorsHolder,
// this should fire when you click the change button, but it does not
colorsContainBlue : function() {
console.log("fired colorsContainBlue");
this.colorsHolder.colors.forEach(function(colorObj) {
if(colorObj.get('color') == 'blue')
return true;
});
return false;
}.property('[email protected]'),
// this is a function called by an action in the template
changeToBlue: function() {
App.color1.set('color','blue');
console.log("changed the color to: " + App.color1.get('color'));
}
});