sproutcore 属性(@each)未更新
我正在分析基本的 todo 应用程序。
为什么当我删除 StatsView
(从主 todos.js 和 todos.handlebars 中)时,todoListController
的 remaining
方法(属性) code> 停止更新自身?
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
不应该密切关注这些变化吗?
I'm analyzing the basic todo application.
Why is it that when I delete the StatsView
(from the main todos.js and from todos.handlebars) the remaining
method (property) of the todoListController
stops updating itself?
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(),
...
});
I can imagine, that this is because with the StatsView
I deleted the binding. But shouldn't it be, that the @each
keeps an eye on the changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SproutCore 进行优化以尽可能少地完成工作。因此,当您删除 StatsView 时,您也删除了关心
.remaining
属性的内容。由于没有任何要求,SproutCore 不会计算它。这就是为什么在访问属性时应始终使用get()
和set()
方法,以便它们可以决定是使用缓存版本还是实际计算属性。SproutCore optimizes to do as little work as possible. So, when you deleted the StatsView, you deleted the thing that cares about the
.remaining
property. Since nothing is asking for it, SproutCore doesn't compute it. This is why you should always use theget()
andset()
methods when accessing properties so that they can decide whether to use the cached version or to actually compute the property.