gpt4 book ai didi

ember.js - 嵌套路由的命名约定是什么?

转载 作者:行者123 更新时间:2023-12-02 05:57:58 24 4
gpt4 key购买 nike

(这个问题与这个jsbin有关)

我有以下路由器配置:

App.Router.map(function() {

this.resource('profile', function () {
this.route('user');
this.route('userEdit');
this.route('company');
this.route('companyEdit');
this.resource('products', function () {
this.route('index');
this.route('show', { path: '/:product_id/show' });
});
});

});

有了这个,ember 数据需要以下 Controller :

  • ProfileIndexController
  • 配置文件用户 Controller
  • ProfileUserEditController
  • ProfileCompanyController
  • ProfileCompanyEditController

以下路线:

  • 个人资料路线
  • ProfileIndexRoute
  • ProfileUserRoute
  • ProfileUserEditRoute
  • 简介公司路线
  • ProfileCompanyEditRoute

以及以下模板:

  • 索引
  • 简介
  • 简介/索引
  • 个人资料/用户
  • 个人资料/用户编辑
  • 简介/公司
  • 简介/公司编辑

但我无法处理嵌套的资源配置文件/产品。我期待 Controller 在:

  • ProfileProductsController
  • ProfileProductsIndexController
  • ProfileProductsShowController

路线在:

  • ProfileProductsIndexRoute
  • ProfileProductsShowRoute

模板位于:

  • 简介/产品
  • 简介/产品/索引

相反,通过链接到 #/profile/products/index,ember 生成以下对象:

generated -> route:products Object {fullName: "route:products"}
generated -> route:products.index Object {fullName: "route:products.index"}
generated -> controller:products Object {fullName: "controller:products"}
Could not find "products" template or view. Nothing will be rendered Object {fullName: "template:products"}
generated -> controller:products.index Object {fullName: "controller:products.index"}
Could not find "products.index" template or view. Nothing will be rendered Object {fullName: "template:products.index"}
Transitioned into 'profile.products.index

这出乎我的意料:产品嵌套在配置文件中!我当然可以更改我的 Controller /路由/模板,但我想了解发生了什么。我看到的问题是顶级“产品”将与嵌套的“配置文件/产品”发生冲突。

关于对象名称(路由/ View /模板/ Controller )的生成,ember 如何处理嵌套资源。这在哪里记录? (专门针对嵌套资源!)

最佳答案

我知道您已经回答了自己的问题,但我或许可以提供更多见解。

检查 this awesome article出去。这是对 Ember 中嵌套资源和路由的精彩解释。

总而言之,任何时候您调用 this.resource()(在您的例子中是 this.resource('products'),您都在创建一个新的命名空间,即使调用本身是嵌套的。

这意味着对 resource 的嵌套调用将生成一个 ProductsController,而不是 ProfileProductsController,以及一个 ProductsView(和 products 模板)而不是 ProfileProductsView。关联的模板将需要 {{outlet}} 来呈现它的子项。

此外,this.resource('products') 将创建一个 ProductsIndexController(和一个 products.index 模板),因此您可以继续并从项目资源中删除嵌套的 this.route('index') 调用。

关于ember.js - 嵌套路由的命名约定是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18382289/

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