gpt4 book ai didi

ember.js - Ember 路由 : Reusing a resource under multiple parent routes

转载 作者:行者123 更新时间:2023-12-05 01:06:37 24 4
gpt4 key购买 nike

我有以下路由设置:

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 时,将使用相同的路由器、 Controller 和 View 。
不幸的是,似乎最后一个条目获胜。

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

最佳答案

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

将帖子下的选择图像重命名为其他内容

this.resource('post',{path:":post_id"},function(){
this.resource('xxx',{path:"xxx/:returncontext"});
});

在路由器中,您可以指定 templateNamecontroller必须重复使用。像这样的东西应该使它可重用
App.xxxRoute = Em.Route.extend({
controllerName: 'selectimage',
templateName: 'selectimage'
});

sample Demo

关于ember.js - Ember 路由 : Reusing a resource under multiple parent routes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19975055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com