我有这个router
:
// app/router.js
Router.map(function() {
this.route('battle', function(){
this.route('combats');
})
});
在战斗路线中,我可以使用以下方法轻松访问战斗模型:
// app/routes/battle/combat.js
this.modelFor('battle');
但是,如果我也想在战斗模板中访问这个模型,事情就会变得复杂:
// app/templates/battle/combats.hbs
<h1>Combats for Battle {{<how to access to the battle>.title}}</h1>
{{#each model as |combat|}}
{{combat.date}}
{{/each}}
我已经解决了从战斗路线向战斗控制器发送属性的问题:
// app/routes/battle/combat.js
setupController: function(controller, model) {
controller.set('content', model);
controller.set('battle', this.modelFor('battle'));
}
但我不知道这是否是正确的方法,在我看来它看起来太间接了,就像你必须做一个很长的解决方法才能使这个属性在模板中可用。