简体   繁体   English

灰烬数据-如何更新记录

[英]Ember data - How to update record

I did implement some code with ember-data talking to a sinatra json-app. 我确实用与sinatra json-app对话的ember-data实现了一些代码。 Method findAll works as expected and load of records. 方法findAll按预期方式工作并加载记录。 Also I did implement the updateRecord-method in the DS.Store.create, but don't really know how to update and commit. 我也确实在DS.Store.create中实现了updateRecord-method,但实际上并不知道如何更新和提交。 Please, see the code here (for sake of brevity, I didn't include the jquery functions): http://pastie.org/3197008 请在此处查看代码(为简洁起见,我未包含jquery函数): http : //pastie.org/3197008

I tried the following: 我尝试了以下方法:

a = Todos.records.objectAt(0).set("text", "should be so")
a.store.commit()

But I get the following error: TypeError: Object (subclass of DS.State) has no method 'enter' 但是我收到以下错误: TypeError: Object (subclass of DS.State) has no method 'enter'

How should I update records? 我应该如何更新记录? Or did I forget to implement something for the update? 还是忘了为更新实现一些东西?

Thanks in advance! 提前致谢!

I had the same problem. 我有同样的问题。 I think this is a bug in ember-data. 我认为这是在余烬数据中的错误。 The problem is that the code was not properly initializing certain substates, and those substates were not state instances but rather state classes. 问题在于代码没有正确初始化某些子状态,而这些子状态不是状态实例,而是状态类。

I fixed the problem by defining a function that generates a new state instance (with properly created substates) each time it is called. 我通过定义一个函数在每次调用时都会生成一个新的状态实例(带有正确创建的子状态)来解决该问题。 You can find my changes here . 您可以在这里找到我的更改。

I also requested that the ember-data folks pull my fix, so hopefully this issue will disappear soon. 我还要求余烬数据专家们来解决我的问题,因此希望这个问题很快消失。 You can view the pull request for discussion. 您可以查看拉取请求以进行讨论。

i had the same problem this morning. 我今天早上有同样的问题。 Use the emberjs git version 使用emberjs git版本

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM