Ember.js 如何在编辑下嵌套子资源
我有下面的路由器Ember.js 如何在编辑下嵌套子资源,ember.js,Ember.js,我有下面的路由器 App.Router.map(function() { this.resource('people', function(){ this.resource('person', { path:'/:person_id' }, function(){ this.resource('addresses', function(){ this.resource('addressTypes'); this.reso
App.Router.map(function() {
this.resource('people', function(){
this.resource('person', { path:'/:person_id' }, function(){
this.resource('addresses', function(){
this.resource('addressTypes');
this.resource('address', { path:'/:address_id' }, function(){
this.route('edit');
});
this.route('create');
});
this.route('edit');
});
this.route('create');
});
这允许我从“人员->人员->地址”进行路由。要编辑人物,我会去人物->人物->编辑(人物)。要编辑地址,我会去:人->人->地址->编辑(地址)。但我想做的是人->人->编辑->地址编辑。也就是说,我想将addressEdit嵌套在(person)编辑路由下,这样,如果我转换到personEdit,它链接到子地址,那么我将能够单击一个地址并直接转到addressEdit。换句话说,尽管person和address是两个不同的模型,但我希望person的编辑包括address的编辑
在编辑(个人ID 1)时,移动到地址(地址ID 11属于个人ID 1),我希望url看起来像:app/#/people/1/edit/addresses/11/edit
以下是我试图用代码表达这一点的失败尝试:
App.Router.map(function() {
this.resource('people', function(){
this.resource('person', { path:'/:person_id' }, function(){
this.resource('addresses', function(){
this.resource('addressTypes');
this.resource('address', { path:'/:address_id' }, function(){
//this.route('edit');
});
this.route('create');
});
//this.route('edit');
this.resource('edit', function(){
this.resource('addresses', function(){
this.resource('addressTypes');
this.resource('addressEdit', { path:'/:address_id' }, function(){
//this.route('edit');
});
this.route('create');
});
});
});
this.route('create');
});
}))
当从/app/people/1转换到/edit时,将路由('edit')更改为资源('edit'..)会立即中断应用程序:“找不到路由person.edit”
你能提供一些指导吗?谢谢。
资源。路由
到的链接现在应该是编辑
。我可能会将其重命名为personEdit
this.resource('personEdit', {path:'edit'}, function(){
非常感谢。简洁正确的回答!要从
person
转换到person edit,我正在使用personController
中的操作;使用代码后,我将操作从this.transitionRoute('person.edit')
更新为this.transitionRoute('personEdit')
。为那些可能不知道的人着想,指定资源会将命名层次结构重置为资源中指定的名称。感谢您填写这些空白,我刚刚做了肩部手术,单手啄食速度很慢:)