Ember.js 从子级导航到父级不工作
在我的用例中,我希望从父路由导航到子路由,并从子路由导航到父路由。第一个案例有效,但第二个案例无效。为什么?怎么了?是renderTemplate中的错误吗Ember.js 从子级导航到父级不工作,ember.js,Ember.js,在我的用例中,我希望从父路由导航到子路由,并从子路由导航到父路由。第一个案例有效,但第二个案例无效。为什么?怎么了?是renderTemplate中的错误吗 App = Ember.Application.create(); App.Router.map(function() { this.resource('parent',function(){ this.resource('child',function(){ }); }); }); App.ChildR
App = Ember.Application.create();
App.Router.map(function() {
this.resource('parent',function(){
this.resource('child',function(){
});
});
});
App.ChildRoute = Ember.Route.extend({
renderTemplate: function(){
this.render('child', {
into: 'application',
controller: 'child'
});
}
});
<script type="text/x-handlebars">
<h1>Ember Sandbox</h1>
<nav>
{{#linkTo 'parent'}} Parent {{/linkTo}}
</nav>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Welcome</h2>
</script>
<script type="text/x-handlebars" data-template-name="parent">
<h2>Parent</h2>
{{#linkTo 'child'}} Child {{/linkTo}}
</script>
<script type="text/x-handlebars" data-template-name="child">
<h2>Child</h2>
{{#linkTo 'parent'}} Parent {{/linkTo}}
</script>
App=Ember.Application.create();
App.Router.map(函数(){
this.resource('parent',函数(){
this.resource('child',function(){
});
});
});
App.ChildRoute=Ember.Route.extend({
renderTemplate:function(){
this.render('child'{
改为:'应用',
控制器:“儿童”
});
}
});
余烬沙箱
{{{#链接到'父'}父{{/linkTo}
{{outlet}}
欢迎
父母亲
{{{linkTo'child}}child{{/linkTo}
小孩
{{{#链接到'父'}父{{/linkTo}
无论何时嵌套资源,emberjs都会提供索引路由(App.ParentIndexRoute)。当您从子资源转换到父资源时,父模板已经呈现,因此它将重定向到索引路由(App.ParentIndexRoute)
在App.ParentIndexRoute中呈现父模板将解决您的问题
App.ParentIndexRoute = Ember.Route.extend({
renderTemplate: function(){
this.render('parent', {into: 'application'});
}
});