简体   繁体   English

在状态root.loaded.updated.inFlight中尝试处理事件`willCommit`

[英]Attempted to handle event `willCommit` on while in state root.loaded.updated.inFlight

I'm learning how to use EmberJS by doing the introductory tutorial form the "Getting started" page. 我正在通过“入门”页面的入门教程学习如何使用EmberJS。 However, when I get to the "Accepting edits" part, I have a bug: 但是,当我进入“接受编辑”部分时,我有一个错误:

Uncaught Error: Attempted to handle event `willCommit` on <Todos.Todo:ember304:3> while in state root.loaded.updated.inFlight. 

The call to Todos.TodoController.acceptChanges() seems to be triggering that error. Todos.TodoController.acceptChanges()的调用似乎是在触发该错误。 The part I'm referring about is this one: http://emberjs.com/guides/getting-started/accepting-edits/ 我所指的部分是这一部分: http//emberjs.com/guides/getting-started/accepting-edits/

After reading up on model lifecycle in Ember - http://emberjs.com/guides/models/model-lifecycle/#toc_in-flight - I still don't get why this bug appears. 在阅读了Ember的模型生命周期后 - http://emberjs.com/guides/models/model-lifecycle/#toc_in-flight-我仍然不明白为什么会出现这个错误。

One work-around is to save the model each time it changes (so every time the value of the <input> changes. Which works fine but would probably perform poorly with a HTTP API (as opposed to fixtures). 一个解决方法是每次更改时保存模型(因此每次<input>的值都会发生变化。这样可以正常工作但是使用HTTP API可能表现不佳(而不是灯具)。

Could this be due to BC breaking changes in the ember-data lib? 这可能是因为BC破坏了ember-data lib中的变化吗? What else could cause this? 还有什么可能导致这个?


Versions of libraries I've used: 我用过的库的版本:

jQuery: 2.0.3 jQuery:2.0.3

Handlebars 1.0.0 把手1.0.0

EmberJS: 1.0.0 RC7 EmberJS:1.0.0 RC7

Ember Data: v0.13-102-g6bdebe7 Ember数据:v0.13-102-g6bdebe7

After reading up on model lifecycle in Ember - http://emberjs.com/guides/models/model-lifecycle/#toc_in-flight - I still don't get why this bug appears. 在阅读了Ember的模型生命周期后 - http://emberjs.com/guides/models/model-lifecycle/#toc_in-flight-我仍然不明白为什么会出现这个错误。

This is not a bug, the in-flight section say's it all: 这不是一个错误,飞行中的部分说的就是这一切:

A record that is in-flight is a dirty record that has been given to the adapter to save the changes made locally. 正在传输的记录是已提供给适配器以保存本地更改的脏记录。 Once the server has acknowledged that the changes have been saved successfully, the record will become clean. 一旦服务器确认已成功保存更改,记录将变为干净。

This means that you are trying to change the record while a previously change made it dirty and a possibly call to this.get('store').save() is still in the doings eg waiting for the server to respond. 这意味着您正在尝试更改记录,而先前的更改使其变脏并且可能调用this.get('store').save()仍在执行中,例如等待服务器响应。 During this time frame you can't make changes to that same record without getting the error. 在此时间范围内,您无法在不收到错误的情况下对同一记录进行更改。

So a solution could be to not trigger this.get('store').save() after a character of the textbox has changed but rather on focus out for example, or even with a explicit button to save the record which you could disable until your server acknowledges it's change, this would not make a request for every character to the server resulting in sluggish performance due to some latency. 因此,一个解决方案可能是在文本框的字符发生变化之后不会触发this.get('store').save() ,而是在焦点输出之后,或者甚至使用显式按钮来保存您可以禁用的记录直到您的服务器确认它发生了变化,这不会向服务器请求每个字符,导致由于某些延迟而导致性能低下。 Hope this makes sense. 希望这是有道理的。

Hope it helps. 希望能帮助到你。

I had this same issue with the Getting Started guide. 我在“入门指南”中遇到了同样的问题。 I solved it by checking if the model was currently saving in acceptChanges : 我通过检查模型当前是否在acceptChanges保存来解决它:

acceptChanges: function() {
  var model = this.get('model')
  if (model.get('isSaving')) { return }

  this.set('isEditing', false)
  model.save()
}

暂无
暂无

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

相关问题 在状态为“ root.loaded.saved”时尝试处理事件“ becameInvalid” - Attempted to handle event `becameInvalid` while in state 'root.loaded.saved' 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 样式加载事件后的 LitElement 阴影根 - LitElement shadow root after styles loaded event JStree:如何将AJAX加载的根节点的状态设置为不确定 - JStree: How to set state of AJAX-loaded root nodes to undetermined 如何从延迟加载的模块访问根状态? - How can I access root state from lazy loaded modules? 为什么更新的 state 没有反映在事件侦听器中:React Native,Hooks - why updated state not reflected inside an event listener: React Native, Hooks 为什么事件处理程序 function 无法获取更新后的 state object 值? - Why the event handler function cannot get the updated state object value? 在执行之前处理外部javascript脚本加载事件 - handle external javascript script loaded event before it's executed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM