2013-08-22 49 views
2

(這個問題是與此相關的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' }); 
     }); 
    }); 

}); 

由此,餘燼數據預計以下控制器:

  • ProfileIndexController
  • ProfileUserController
  • ProfileUserEditController
  • ProfileCompanyController
  • ProfileCompanyEditController

以下路線:

  • ProfileRoute
  • ProfileIndexRoute
  • ProfileUserRoute
  • ProfileUserEditRoute
  • P rofileCompanyRoute
  • ProfileCompanyEditRoute

而下面的模板:

  • 指數
  • 輪廓
  • 資料/指數
  • 資料/用戶
  • 資料/ USEREDIT
  • PROFI LE /公司
  • 資料/ companyEdit

但我無法處理嵌套的資源配置文件/產品。

  • ProfileProductsController
  • ProfileProductsIndexController在
  • ProfileProductsShowController

的路線:我在期待控制器

  • ProfileProductsIndexRoute
  • ProfileProductsShowRoute

,並在模板:

  • 資料/產品
  • 資料/產品/指數

相反,通過以下鏈接#/profile/products/index,燼正在生成以下對象:

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 

這對我來說意想不到:產品嵌套在配置文件中!我當然可以改變我的控制器/路線/模板,但我想知道發生了什麼。我看到的問題是頂級「產品」會與嵌套的「配置文件/產品」發生衝突。

如何處理嵌套資源,關於對象名稱(路由/視圖/模板/控制器)的生成。這在哪裏記錄? (專門爲嵌套資源!)

回答

0

寫了這麼長的問題後,我意識到這是一個documented功能。

目前還不清楚在頂級資源和嵌套資源被稱爲相同的情況下會發生什麼。我想這會導致衝突。我會說燼寶在這裏假設太多了:只有一種「產品」,這不一定是這種情況。

5

我知道你已經回答了你自己的問題,但我可能能夠提供更多的見解。

檢查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')調用。