2013-08-06 85 views
0

我有一個視圖,其中有一個命名插座。這個視圖不與控制器關聯,不能用於我的用例。我似乎無法渲染到該命名插座。我會如何正確瞄準它?Ember.js渲染到視圖的插座

如果視圖被命名爲App.UnassociatedView,命名出口{{outlet potatoOutlet}},那我想關聯的控制器和視圖分別爲App.PotatoControllerApp.PotatoView,我該如何使這項工作?

我已經試過

App.ApplicationRoute = Ember.Route.extend({ 
    renderTemplate: function() { 
     this.render(); 
     this.render('potato', {outlet: 'potatoOutlet', controller: this.controllerFor('potato')}); 
    } 
}); 

App.ApplicationRoute = Ember.Route.extend({ 
    renderTemplate: function() { 
     this.render(); 
     this.render('potato', {outlet: 'potatoOutlet', controller: this.controllerFor('potato'), into: 'application'}); 
    } 
}); 

App.ApplicationRoute = Ember.Route.extend({ 
    renderTemplate: function() { 
     this.render(); 
     this.render('potato', {outlet: 'potatoOutlet', controller: this.controllerFor('potato'), into: 'unassociated'}); 
    } 
}); 

這裏是一個js小提琴:http://jsfiddle.net/wmarbut/X8Mu4/

編輯˚F或清晰

我在小提琴的評論文本中有這個,但忘了把它放在這裏。將插座移動到根級別對我來說不是一個選項b/c這樣做的目標是在頁面加載時讓UnassociatedView實際生成插座。我的代碼,使網點實際工作,我只是無法連接它們。

回答

0

我已經解決了你的jsfiddle有點。

App.IndexRoute = Ember.Route.extend({ 
    renderTemplate: function(){ 
    this._super(); 
    var controller = this.controllerFor('potato'); 
    this.render('potato', {outlet: 'potatoOutlet', controller: controller}); 
    } 
}) 

http://jsfiddle.net/X8Mu4/5/

  • 感動出口到根級別
  • 感動renderTemplate覆蓋到IndexRoute(因爲這是被送到)
  • 啓用LOG_TRANSITIONS來輔助調試路由

我建議不要覆蓋ApplicationView的模板作爲索引。導致混亂。

您也不必顯式創建ApplicationView。見:Do I have to explicitly create an `ApplicationView` and an `ApplicationController` for every Ember.js application?

+0

啊,所以這裏的問題是,實際的unassociated-view在加載時實際上動態地創建了N個視圖,所以出口不能在根級別,並且必須位於該視圖內。感謝您的幫助和時間! – wmarbut