我有一个类似的组件:
App.TestCompComponent = Ember.Component.extend({
title: 'Test Component',
disablePastChanged: function(){
alert('disable past changed');
}.observes('disablePast').on('init'),
prop1Changed: function(){
alert('Prop1 changed');
}.observes('prop1').on('init')
});
和把手模板如下:
{{#test-comp disablePast=disablePast prop1=prop1}}
{{/test-comp}}
现在当从父组件设置此组件的任何属性/ attrs时,如this.set('disablePast',false),两个观察者都被触发(基本上所有的attrs观察者都被触发)。这是正确的行为吗?到目前为止,我担心它应该只解雇改变的财产/阁楼。
JS Bin here - 为什么它在启动时激活观察者,这些属性没有被设置在任何地方? 当您单击按钮并且它仅设置一个属性/ attrs时,它会为属性激发观察者两次。
我在这里做错了什么?
更新
或者我们应该为组件使用新的生命周期钩子:
didInitAttrs
didReceiveAttrs
willRender
但是有了这些钩子,我不知道哪个属性实际发生了变化。它为我提供了更新的属性。
谢谢!
如果有人正在寻找解决方案: http://discuss.emberjs.com/t/ember-1-13-attrs-call-property-change-on-all-observers/8212