【发布时间】:2012-12-06 06:39:08
【问题描述】:
我有一个具有计算属性的视图。当依赖项被更新时,观察者会正确触发,但计算属性不会。可能是什么原因?
在车把中:
{{#view viewName currencyBinding="changingValue"}}
{{view.prefix}}
{{/view}}
在视图中:
prefix: (function() {
//does not get called!!!
console.log('computed property fired');
return this.get('currency');
}).property('currency')
observeCurrency: (function() {
//gets called!
return console.log('observer fired');
}).observes('currency')
当 'changedValue' 更新但属性没有更新时,观察者会被触发! 另外,如果我在观察者中设置“前缀”:
observeCurrency: (function() {
//gets called!
console.log('observer fired');
return this.set('prefix', this.get('currency'));
}).observes('currency')
除非我明确地重新呈现视图,否则我的 html 不会得到更新。为什么会这样?
【问题讨论】:
-
除非我遗漏了一些你不必像这样包装你的计算属性的东西,它应该是
computedPropertyName: function { ... }.property('dependency')
标签: ember.js javascript-framework handlebars.js