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'));
}
});