鉴于以下观点:
<script type="text/x-handlebars">
<article>{{outlet "foo"}}</article>
<aside>{{outlet}}</aside>
</script>
<script type="text/x-handlebars" data-template-name="base/index">
<h2>Base</h2>
{{view Ember.Select
contentBinding=model
optionValuePath="content.id" optionLabelPath="content.name"
prompt="Select a child"
valueBinding="selectedChild"}}
<div id="child">
<p>I want the child rendering here</p>
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" data-template-name="foo">
<h2>Foo</h2>
</script>
<script type="text/x-handlebars" data-template-name="child">
<h2>Child</h2>
<p>Child: {{id}} {{name}}</p>
<pre>{{controller}}</pre>
</script>
这个应用程序:
var App = Ember.Application.create({
LOG_TRANSITIONS: true,
LOG_ACTIVE_GENERATION: true,
LOG_VIEW_LOOKUPS: true
});
App.Router.map(function() {
this.resource('base', function() {
this.resource('child', {path: ':child_id'});
});
});
App.IndexRoute = Ember.Route.extend({
beforeModel: function() {
this.transitionTo('base');
}
});
App.BaseRoute = Ember.Route.extend({
renderTemplate: function() {
this.render('foo', {into: 'application', outlet: 'foo'});
}
});
App.BaseIndexRoute = Ember.Route.extend({
model: function() {
return children;
}
});
App.ChildController = Ember.ObjectController.extend();
App.BaseIndexController = Ember.ObjectController.extend({
selectedChild: null,
selectedChildChanged: function() {
var id = this.get('selectedChild');
this.transitionToRoute('child', id);
}.observes('selectedChild')
});
App.ChildRoute = Ember.Route.extend({
model: function(params) {
return children[params.child_id - 1];
}
});
var children = [
{id: 1, name: 'Foo Goggins'},
{id: 2, name: 'Bar McFudger'},
{id: 3, name: 'Gia Goggins-McFudger'}
];
我期望子视图被渲染到{{outlet}}
内部,div#child
但它会渲染到主应用程序出口。
您可以在这里看到一个工作示例http://jsbin.com/docuj/10/edit