<編輯日期= 「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