[英]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.