2014-10-04 81 views
2

我正在編寫一個組件,我需要訪問當前路由的模型; 在組件的模板,我想這樣做:在Ember組件中獲取當前路由的模型

{{#each color in model}} 
    ... 
{{/each}} 

我會在不同的路由使用這個組件,不同型號

我如何可以訪問組件內的電流路徑的模式?

Ember.Component.extend({ 
    didInsertElement: function() { 
     console.log(this.get('controller') //this is not the route's controller 
     console.log(this.get('controller').get('model')); //undefined of course 
    } 
}); 

回答

2

將它傳遞給組件。

{{my-comp model=model foo=model bar=model}} 

在上面的例子中,您的組件modelfoo的範圍內,並且bar將模型。

+0

太簡單了!謝謝 – 2014-10-04 21:03:51

相關問題