Ember渲染到指定插座内的插座

时间:2014-12-02 23:42:06

标签: ember.js outlet

鉴于这些模板

<script type="text/x-handlebars">
  <h3>Application outlet:</h3>
  <div class="outlet">
    {{outlet}}
  <div>

  <h3><code>'base'</code> outlet:</h3>
  <div class="outlet base-outlet">
    {{outlet 'base'}}
  </div>
</script>

<script type="text/x-handlebars" data-template-name="index">
  <h1>I am the application index, I should be in the application outlet.</h1>
</script>

<script type="text/x-handlebars" data-template-name="foo">
  <p>I am foo, I have my own outlet here:</p>
  <h3>Foo Outlet:</h3>
  <div class="outlet foo-outlet">  
    {{outlet}}
  </div>
</script>

<script type="text/x-handlebars" data-template-name="foo/index">
  <p>I am foo index, I should be inside <code>#foo-outlet</code> (green border)</p>
</script>

这些路线:

App.Router.map(function() {
  this.resource('foo', function() {
    this.resource('bar');
  });
});

App.IndexRoute = Ember.Route.extend({ 
  afterModel: function() {
    this.transitionTo('foo.index');
  }
});

App.FooRoute = Ember.Route.extend({
  renderTemplate: function() {
    this.render({into: 'application', outlet: 'base'});
  }
});

我希望foo/index模板可以在{{outlet}}模板中包含的foo内呈现,但是它会呈现在应用程序插座中,这里有一个实例:{ {3}}

请注意,如果我在this._super()中拨打renderTemplate,我会在正确的位置获得foo/index种类,但foo模板会呈现两次。

更新:我想要实现的目标如下:

  1. 应用程序有一个指定的插座,让我们说'sidebar'
  2. 路径可以将包装器呈现到此侧边栏插座中,该插座包含其自己的(未命名的)插座
  3. 然后该路线的子路线应在包装内的插座中呈现。
  4. 因此,在上面的示例中,foo路由应该将其包装器呈现到'base'出口,然后应该在其中呈现其子路由(示例中为foo/index)的内容包装器内的插座(示例中具有类foo-outlet的插座)。

0 个答案:

没有答案