2015-09-03 37 views
0

下面是简单的代码(恩伯1.13.7):如何观测基地组件属性

主要成份:

export default Ember.Component.extend({ 
    tagName: 'a', 
    classNameBindings: ['isTestCom:test'], 
    didInsertElement: function() { 
    this._super.apply(this, arguments); 
    this.$().on('click', Ember.run.bind(this, function() { 
     this._click(); 
    })); 
    }, 
    willDestroyElement: function() { 
    this._super.apply(this, arguments); 
    this.$().off('click'); 
    }, 

    _click:function(){ 
    this.toggleProperty('isTest'); 
    }, 
    isTest:false, 
    isTestCom: Ember.computed('isTest',function(){ 
    return this.get('isTest'); 
    }), 
}); 

扩展组件:

export default MainComponent.extend({ 
    isTestChiid: Ember.computed('isTestCom',function(){ 
    console.debug('working'); 
    }) 
}); 

的问题是,isTestChild从未火灾。任何想法

+0

您是否尝试过访问组件模板中的“isTestChild”属性?只有在访问CP时才会调用该函数。让我知道它是否有效。谢谢。 – phkavitha

+0

你是对的......没有意识到这一点 – sepetukas

回答

0

如果isTestCom某处引用(模板或JavaScript代码),并触发change事件,但isTestChild不是那么组件属性将如何观察电源是非常有益的使用:

export default MainComponent.extend({ 
    isTestChild: Ember.observer('isTestCom', function() { 
    console.debug('working'); 
    }) 
}); 

如果isTestChild在模板代码中引用或然后JavaScript代码使用方法:

export default MainComponent.extend({ 
    isTestChild: Ember.computed('isTestCom', function() { 
    console.debug('working'); 
    }) 
}); 

您还错误地输入属性名称,它应该是isTestChild而不是isTestChid

相关问题