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