Ember.js 余烬路由:在多个父路由下重用资源

Ember.js 余烬路由:在多个父路由下重用资源,ember.js,Ember.js,我有以下路由设置: this.resource('blog',function(){ this.resource('selectimage',{path:"selectimage/:returncontext"},function(){}); }); this.resource('post',{path:":post_id"},function(){ this.resource('selectimage',{path:"selectimage/:returncontext"},

我有以下路由设置:

this.resource('blog',function(){
    this.resource('selectimage',{path:"selectimage/:returncontext"},function(){});
});

this.resource('post',{path:":post_id"},function(){
    this.resource('selectimage',{path:"selectimage/:returncontext"},function(){});
});
我所期望的是,当导航到blog.selectimage和post.selectimage时,将使用相同的路由器、控制器和视图。 不幸的是,最后一个参赛者似乎获胜了

当导航到selectimage时,是否可以在不离开父上下文(帖子/博客)的情况下实现这一点
(显然,我可以从基本的selectimages类继承,但我希望有一些通用的ember方法可以做到这一点。)

对于两个不同的路由,您不能有相同的资源名称,因为ember更依赖于命名约定。但是Ember提供了重用相同控制器和模板的方法

将post下的selectimage重命名为其他内容

this.resource('post',{path:":post_id"},function(){
   this.resource('xxx',{path:"xxx/:returncontext"});
});
在路由器中,您可以指定必须重用的
模板名
控制器
。像这样的东西应该可以让它重复使用

App.xxxRoute = Em.Route.extend({
  controllerName: 'selectimage',
  templateName: 'selectimage'
});

样本

不错。我不知道你可以像在路由中那样指定控制器和模板。。。刚刚检查了文档@:controllerName和templateName,但没有提及。查看源代码中的render方法,我发现您还可以指定viewName。很高兴这对您有所帮助:)Ember Docs正在变得越来越好。相信它会很快达到最佳状态