2012-02-14 53 views
0

我在分析基本的todo应用程序。sproutcore属性(@each)未更新

为什么当我删除StatsView(来自主todos.js和todos.handlebars)todoListControllerremaining方法(属性)会停止自行更新?

Todos.todoListController = SC.ArrayController.create({ 
    ... 
    remaining: function() { 
    console.log('remaining');//doesn't apear in the console 
    return this.filterProperty('isDone', false).get('length'); 
    }.property('@each.isDone').cacheable(), 
    ... 
}); 

我能想象,这是因为与StatsView我删除了绑定。但是不应该这样,@each会关注这些变化吗?

回答

0

SproutCore优化尽可能少的工作。所以,当你删除StatsView时,你删除了关注.remaining属性的东西。由于没有要求它,SproutCore不计算它。这就是为什么在访问属性时应始终使用get()set()方法,以便他们可以决定是使用缓存版本还是实际计算属性。