如何在 Ember 中创建正确的编辑路径?
How to make a proper edit route in Ember?
目前我的路线是这样的:
this.route('cards', function() {
this.route('all');
this.route('card', {path: ':id'});
this.route('new');
});
我想为卡片制作一条 edit
路线。我希望制作像 cards/1/edit
这样的路线可以使其可编辑。但我不确定如何进行。如果我创建一个像 cards/1/edit
这样的路由,我如何在该路由上显示编辑表单并向后端发送 PATCH 请求。
this.route('cards', function() {
this.route('all');
this.route('card', {path: ':id'}, function() {
this.route('edit');
});
this.route('new');
});
但是,如果我创建一个像 cards/edit/1
这样的简单路由,我可以将数据发送到后端,但它会像下面这样:
this.route('cards', function() {
this.route('all');
this.route('card', {path: ':id'});
this.route('new');
this.route('edit', {path: ':id'});
});
这会引发错误,指出 cards/card
不是路线。
这是我过去所做的:
this.route('cards', function() {
//An index route for cards is implied.
this.route('add', {path: '/add'});
this.route('update', {path: '/update/:id'});
});
相应的 url(以隐含的 cards/index.hbs 开头)将是:
希望这对您有所帮助,
杰夫
这是我实际使用的路线:
this.route('cards', function() {
this.route('all');
this.route('card', {path: '/:card_id'}, function() {
this.route('edit');
});
this.route('new');
});
然后我要去编辑路线(cards/1/edit
)修改卡片
感谢@Visualjeff
目前我的路线是这样的:
this.route('cards', function() {
this.route('all');
this.route('card', {path: ':id'});
this.route('new');
});
我想为卡片制作一条 edit
路线。我希望制作像 cards/1/edit
这样的路线可以使其可编辑。但我不确定如何进行。如果我创建一个像 cards/1/edit
这样的路由,我如何在该路由上显示编辑表单并向后端发送 PATCH 请求。
this.route('cards', function() {
this.route('all');
this.route('card', {path: ':id'}, function() {
this.route('edit');
});
this.route('new');
});
但是,如果我创建一个像 cards/edit/1
这样的简单路由,我可以将数据发送到后端,但它会像下面这样:
this.route('cards', function() {
this.route('all');
this.route('card', {path: ':id'});
this.route('new');
this.route('edit', {path: ':id'});
});
这会引发错误,指出 cards/card
不是路线。
这是我过去所做的:
this.route('cards', function() {
//An index route for cards is implied.
this.route('add', {path: '/add'});
this.route('update', {path: '/update/:id'});
});
相应的 url(以隐含的 cards/index.hbs 开头)将是:
希望这对您有所帮助,
杰夫
这是我实际使用的路线:
this.route('cards', function() {
this.route('all');
this.route('card', {path: '/:card_id'}, function() {
this.route('edit');
});
this.route('new');
});
然后我要去编辑路线(cards/1/edit
)修改卡片
感谢@Visualjeff