2015-10-17 56 views
0
[email protected] 
[email protected] 

我傳遞一個簡單的模型到一個組件,但得到以下對象(我看起來像實際的燼數據模型是在value屬性下)。爲什麼模型指向這個而不是實際的模型?傳遞組件和獲得奇怪的結果

enter image description here

路線

export default Ember.Route.extend({ 

    model() { 
    return this.store.createRecord('employee'); 
    } 

}) 

模板

{{log model}} {{!-- logging here correctly displays the ember-data object --}} 
{{my-component model=model}} 

我也試過這樣:

<my-component model={{model}} /> <!-- which prints the folowing in HTML <model-editor model="<[email protected]:employee::ember395:null>"></model-editor>--> 

成分(我組分)

export default Ember.Component.extend({ 
    layout, 

    didReceiveAttrs() { 
    console.log(this.attrs.model); //Prints the Object above 
    } 

}); 

回答

1

你可以使用的this.get('model')代替this.attrs.model得到你所期望的行爲。

但是,如果您想繼續使用this.attrs.model,則需要明確引用this.attrs.model.value才能獲得model屬性值。

這是因爲model屬性通過它的value和方式來更新它 - update函數。

該概念與mut助手類似。 You can read more about this behavior here.