简体   繁体   English

尝试处理事件“ pushedData” <testapp@model:testroute::ember1700:1> 处于状态root.loaded.updated.invalid时

[英]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()
      }
    }
  }
});

See here for more information. 有关更多信息,请参见此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试处理事件 `pushedData`<appname@model:post::ember622:17> 在 root.deleted.inFlight 状态下 - Attempted to handle event `pushedData` on <appname@model:post::ember622:17> while in state root.deleted.inFlight 在状态root.loaded.updated.inFlight中尝试处理事件`willCommit` - Attempted to handle event `willCommit` on while in state root.loaded.updated.inFlight 在状态为“ root.loaded.saved”时尝试处理事件“ becameInvalid” - Attempted to handle event `becameInvalid` while in state 'root.loaded.saved' Ember-data - “在状态root.deleted.saved中尝试在* record *上处理事件`deleteRecord`。” - Ember-data - “Attempted to handle event `deleteRecord` on *record* while in state root.deleted.saved.” 未捕获错误:在状态rootState.loaded.updated.uncommitted中尝试处理事件`loadedData` - Uncaught Error: Attempted to handle event `loadedData` while in state rootState.loaded.updated.uncommitted Ember JS,在状态为root.loaded.updated.uncommitted的Transformer handeling事件`didCommit`中解析数据时出错。“ - Ember JS, Error while parsing Data in Transformer handeling event `didCommit` in state root.loaded.updated.uncommitted." “尝试处理事件`reloadRecord` <App.User:ember820:me> 处于root.deleted.saved状态时。 ” - “Attempted to handle event `reloadRecord` on <App.User:ember820:me> while in state root.deleted.saved. ” 错误:删除记录模型余烬时尝试处理事件`didSetProperty` - Error: Attempted to handle event `didSetProperty` when Deleting record model ember 灰烬未捕获的错误:试图处理事件`didSetProperty` - Ember Uncaught Error: Attempted to handle event `didSetProperty` Ember商店刷新问题! 错误:无法响应状态rootState.loaded.updated.uncommitted中的事件didChangeData - Ember store refresh issue! Error: could not respond to event didChangeData in state rootState.loaded.updated.uncommitted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM