[英]Ember nested routes
我有一个模型工厂和一个相关的模型工厂,其网址应为:
/plants
/plants/new
/plants/some-plant-id/planting/new
添加种植的路线在url中起作用,并显示正确的添加形式。 问题是对种植采取行动/新提交无效。
安慰
ember.debug.js:19699 Uncaught Error: Nothing handled the action 'savePlanting'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.
我猜测问题出在我在router.js中构造路由的方式,但不确定。 只有一个控制器-app / controllers / application.js,这是最小的
这是我的一些代码
app / routes / planting / new.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.createRecord('planting');
},
actions: {
savePlanting(newPlanting) {
console.log("trying to save...");
newPlanting.save().then(() => this.transitionTo('planting'));
},
willTransition() {
//rollbackAttributes() removes the record from the store
//if the model 'isNew'
this.controller.get('model').rollbackAttributes();
}
}
});
router.js
...
this.route('plants', function() {
this.route('new');
this.route('edit', { path: '/:plant_id/edit' });
this.route('planting', { path: '/plants/:plant_id/planting' }, function(){
this.route('new');
});
});
...
顺便说一句,我的模板目录就像
app/templates/plants
app/templates/plants/new.hbs
app/templates/plants/planting/new.hbs //plantings dir in plants
路线目录是
app/routes/plants
app/routes/planting
我究竟做错了什么?
我认为您的问题是您想在模板中使用route
中的操作。
为了做到这一点,您应该使用route-action
helper( https://github.com/DockYard/ember-route-action-helper )。
否则它将在控制器中寻找动作:)
如果您看到保存新种植的ajax请求转到后端,则也可能是某种原因导致该操作冒泡(这就是错误消息的第二部分所指)。
您应该做的一件事是在动作处理程序newPlanting.save()
返回promise,并查看它是否有所改变。 另外,请向我们显示触发操作的模板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.