<编辑日期= “2013年3月11日” >
我已经推了this repository in GitHub。这是一个概念性的应用程序,它使用renderTemplate
这种方式有点像你所描述的。
< /编辑>
在你的孩子的路线,使用renderTemplate
挂钩,以告诉应用程序来呈现特定的模板在特定{{outlet}}
。例如:
Source Fiddle
App.Router.map(function() {
this.resource('matches', { path: 'matches' }, function() {
this.route('match', { path: 'match/:match_id' });
});
});
App.MatchesRoute = Em.Route.extend({
model: function() {
return App.Match.find();
},
setupController: function(controller, model) {
model = App.Match.find();
controller.set('content', model);
},
renderTemplate: function() {
this.render('matches', {
into: 'application'
})
}
});
App.MatchesMatchRoute = Em.Route.extend({
model: function(params) {
return App.Match.find(params.match_id);
},
setupController: function(controller, model) {
controller.set('content', model);
},
renderTemplate: function() {
this.render('match', {
into: 'application'
})
}
});
这MatchesMatchRoute
是设置以使它的模板(matches/match
)插入application
模板。而且由于只有一个{{outelet}}
这个模板(见下文把手),我们没有指定任何东西:
<script type="text/x-handlebars">
<h1>App</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="matches">
<h2>Matches</h2>
<ul>
{{#each match in controller}}
<li>
{{#linkTo matches.match match}}
{{match.title}}
{{/linkTo}}
</li>
{{/each}}
</ul>
</script>
<script type="text/x-handlebars" data-template-name="match">
<h3>{{title}}</h3>
<p>{{description}}</p>
</script>
如果你有多个网点的情况下,你必须哈默尔他们,就像在车把如下:
<script type="text/x-handlebars">
<h1>App</h1>
{{outlet main}}<br />
{{outlet nested}}
</script>
然后你的路线也必须指定插座。例如:
Source Fiddle
[...route code...]
renderTemplate: function() {
this.render('content', {
into: 'application',
outlet: 'main'
});
this.render('buttons', {
into: 'application',
outlet: 'nested'
});
}
[...route code...]
非常感谢您的令人难以置信的详细的解答。今天晚上,当我有时间去研究它时,我会仔细研究一下。 :) – ardavis 2013-03-11 11:16:12