2013-08-06 83 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