EmberJS,如何不渲染父视图

时间:2015-12-21 12:00:13

标签: javascript ember.js ember-cli ember-2.0.0

我有router

// app/router.js
Router.map(function() {
  this.route('battles', function(){
    this.route('battle', { path: ':id' }, function(){
      this.route('combats', function() {
        this.route('new');
      });
    });
  });
});

这些templates

  // app/templates/battles.hbs
  {{#each model as |battle|}}
    {{battle.name}}
  {{/each}}
  {{outlet}}

  // app/templates/battles/battle/combats.hbs
  {{#each model as |combat|}}
    {{combat.date}}
  {{/each}}

  // app/templates/battles/battle/combats/new.hbs
  {{input type="text" value=date}}
  <button {{action "createCombat"}}>Create Combat</button>

所以这是为每个route

呈现的内容
  route: /battles
  -> app/templates/battles.hbs

  route: /battles/B2/combats
  -> app/templates/battles.hbs
  -> app/templates/battles/battle/combats.hbs

  route: /battles/B2/combats/new
  -> app/templates/battles.hbs
  -> app/templates/battles/battle/combats.hbs

因此,对于路线/battles/B2/combats/new,不会呈现模板app/templates/battles/battle/combats/new.hbs。这有一个快速解决方法:

  // app/templates/battles/battle/combats.hbs
  {{#each model as |combat|}}
    {{combat.date}}
  {{/each}}
  {{outlet}}

然后路线呈现:

  route: /battles/B2/combats/new
  -> app/templates/battles.hbs
  -> app/templates/battles/battle/combats.hbs
  -> app/templates/battles/battle/combats/new.hbs

我不希望在渲染combat/new表单时呈现战斗列表。我想这样:

  route: /battles/B2/combats/new
  -> app/templates/battles.hbs
  -> app/templates/battles/battle/combats/new.hbs

我如何创建此设置?

0 个答案:

没有答案