嵌套路由的命名约定是什么?

dan*_*ast 2 ember.js ember-data

(这个问题与这个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' });
        });
    });

});
Run Code Online (Sandbox Code Playgroud)

有了这个,ember数据需要以下控制器:

  • ProfileIndexController
  • ProfileUserController
  • ProfileUserEditController
  • ProfileCompanyController
  • ProfileCompanyEditController

以下路线:

  • ProfileRoute
  • ProfileIndexRoute
  • ProfileUserRoute
  • ProfileUserEditRoute
  • ProfileCompanyRoute
  • ProfileCompanyEditRoute

以下模板:

  • 指数
  • 轮廓
  • 资料/指数
  • 资料/用户
  • 资料/ USEREDIT
  • 资料/公司
  • 资料/ companyEdit

但我无法解决嵌套的资源配置文件/产品.我期待控制器在:

  • 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
Run Code Online (Sandbox Code Playgroud)

这对我来说意外:产品嵌套在配置文件中!我当然可以更改我的控制器/路由/模板,但我想了解发生了什么.我看到的问题是顶级"产品"会与嵌套的"个人资料/产品"发生冲突.

ember如何处理嵌套资源,关于对象名称(路由/视图/模板/控制器)的生成.这记录在哪里?(特别是对于嵌套资源!)

Fee*_*ech 5

我知道你已经回答了自己的问题,但我可以提供更多的见解.

检查这篇很棒的文章.这是对Ember中嵌套资源和路由的一个很棒的解释.

总而言之,无论何时调用this.resource()(在您的情况下,this.resource('products')您正在创建新的命名空间,即使调用本身是嵌套的).

这意味着嵌套调用resource将产生ProductsController,不ProfileProductsController,还有一个ProductsView(和products模板),而不是一个ProfileProductsView.关联的模板将需要{{outlet}}渲染它的子项.

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