我正在尝试使用计算属性来观察数组中每个元素的特定属性的变化。这是小提琴。单击更改按钮,计算的属性不会触发。为什么?
这是小提琴: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('colorsHolder.@each.color'),
// 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'));
}
});