2015-09-03 69 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

相關問題