[英]Attempted to handle event `pushedData` on <appname@model:post::ember622:17> while in state root.deleted.inFlight
[英]Attempted to handle event `pushedData` on <testapp@model:testroute::ember1700:1> while in state root.loaded.updated.invalid
我有一个名为“ testroute ”的路由 (本地主机:8080 / testroute)。
它有一个记录。 我尝试对其进行编辑(localhost:8080 / testroute / edit / 1)。 我给出了新的价值观并提交了。 这些值无法通过服务器端验证,并且抛出了错误消息和状态代码422 。
然后,我决定不再对其进行编辑。 我从这里本身走了另一条名为“ nextroute ”的路由(本地主机:8080 / nextroute)。
现在,我再次尝试去“ testroute”(本地主机:8080 / testroute)。 它因此未去,在控制台我得到的错误是“试图处理事件pushedData
上,而在状态root.loaded.updated.invalid。”
我用来用已编辑的值进行ajax调用的是
this.get('model').save().then(function(response){
console.log('response',response);
//code
},function(error){
console.log('error',error);
//code
});
当我刷新页面时,我可以转到“ testroute”(localhost:8080 / testroute)。 但是出现此错误后,我无法打开。
该记录在ember-date中处于修改状态(我在ember检查器中看到了它)。 当我刷新它时,它将进入干净状态。
据我所知,您的服务器无法处理您的发布/补丁请求并返回了错误。 因此,您的模型处于无效状态。 一旦返回错误,您应该做的是回滚模型:
var model = this.get('model')
model.save().then(function(response){
console.log('response',response);
//code
},function(error){
console.log('error',error);
model.rollbackAttributes();
});
编辑:
如果需要在离开页面之前将模型保持在其状态,则应利用路线的willTransition
事件,例如:
Ember.Route.extend({
actions: {
willTransition: function(transition) {
if (this.controller.get('model.errors')) {
Ember.Logger.debug('model will be reverted');
this.controller.get('model').rollbackAttributes()
}
}
}
});
有关更多信息,请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.