2013-10-10 40 views
1

創建一個嵌套的路線我有我的資源之一嵌套編輯路線:與動態段Ember.js

@resource 'organization', path: 'organizations/:organization_id', -> 
    @resource 'organization.edit', path: '/edit' 

我鏈接到它就像這樣(使用Emblem.js):

linkTo 'organization.edit' organization | Edit 

不幸的是,這會導致像網址:

/organizations/4# 

而不是預期的:

/organizations/4/edit 

任何想法爲什麼會發生這種情況?我嘗試了很多路由語法。刪除path對於organization.edit什麼都不做,因爲完整的path: 'organization/:organization_id/edit

回答

1

您應該能夠通過使用這種類型的嵌套結構得到您想要的結果:

App.Router.map(function() { 
    this.resource("organizations", function(){ 
    this.resource("organization", { path: "/:organization_id" }, function(){ 
     this.route("edit"); 
    }); 
    }); 
}); 

JSBin example

+1

你的JSBin會訣竅。實際上,我甚至不需要將最外層的「組織」嵌套在一起。我的錯誤是使用語法'linkTo'organization.edit'organization'而不是'linkTo'organization.edit'this'。通過您的JSBin代碼讀取顯示我的錯誤。感謝您輸入! – nullnullnull

0

你在正確的軌道上,但@resource是真正用於對象,例如,組織。如果要定義一個動作(不嵌套資源),你會想用@route,即:

@resource 'organization', path: 'organizations/:organization_id', -> 
    @route 'edit' 

我認爲,應該給你預期的行爲/路由。

+0

感謝您的快速回復!不幸的是,這個設置仍然存在問題。如果您有任何其他想法,請按照我的方式發送給他們。 – nullnullnull

0

爲什麼不使用這樣的事情:

@resource 'organization', -> 
    @route "edit", 
    path: "/:organization_id/edit"