[英]Attempted to handle event `pushedData` on <testapp@model:testroute::ember1700:1> while in state root.loaded.updated.invalid
I have a route named ' testroute ' (localhost:8080/testroute). 我有一个名为“ testroute ”的路由 (本地主机:8080 / testroute)。
It has one record. 它有一个记录。 I tried to edit it (localhost:8080/testroute/edit/1).
我尝试对其进行编辑(localhost:8080 / testroute / edit / 1)。 I gave new values and submitted.
我给出了新的价值观并提交了。 The values got failed to cross server side validation and error message was thrown with the status code 422 .
这些值无法通过服务器端验证,并且抛出了错误消息和状态代码422 。
Then I decided not to edit it anymore. 然后,我决定不再对其进行编辑。 From here itself I went another route named ' nextroute ' (localhost:8080/nextroute).
我从这里本身走了另一条名为“ nextroute ”的路由(本地主机:8080 / nextroute)。
Now, again I tried to go to 'testroute' (localhost:8080/testroute). 现在,我再次尝试去“ testroute”(本地主机:8080 / testroute)。 It didnot go and in console I got error as "Attempted to handle event
pushedData
on while in state root.loaded.updated.invalid." 它因此未去,在控制台我得到的错误是“试图处理事件
pushedData
上,而在状态root.loaded.updated.invalid。”
What I used to make ajax call with the edited values is 我用来用已编辑的值进行ajax调用的是
this.get('model').save().then(function(response){
console.log('response',response);
//code
},function(error){
console.log('error',error);
//code
});
When I refresh the page I can go to 'testroute' (localhost:8080/testroute). 当我刷新页面时,我可以转到“ testroute”(localhost:8080 / testroute)。 But after this error come I can't open.
但是出现此错误后,我无法打开。
The record was in modified state in ember-date (I saw it in ember inspector). 该记录在ember-date中处于修改状态(我在ember检查器中看到了它)。 When I refresh it only it goes to clean state.
当我刷新它时,它将进入干净状态。
Fom what I can tell, your server couldn't process your post/patch request and returned an error. 据我所知,您的服务器无法处理您的发布/补丁请求并返回了错误。 Therefore, your model is in an invalid state.
因此,您的模型处于无效状态。 What you should do, is, once the error is returned, to rollback your model:
一旦返回错误,您应该做的是回滚模型:
var model = this.get('model')
model.save().then(function(response){
console.log('response',response);
//code
},function(error){
console.log('error',error);
model.rollbackAttributes();
});
EDIT: 编辑:
If you need to keep the model in its state until you leave the page, you should make use of the willTransition
event of your route, eg: 如果需要在离开页面之前将模型保持在其状态,则应利用路线的
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.