如何重新加载余烬数据记录? [英] How to reload an ember data record?

查看:77
本文介绍了如何重新加载余烬数据记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的路由器和ember数据转换11.



我需要强制ember-data从一个记录中重新加载数据服务器。使用 App.MyRecord.find (2)在 setInterval 函数中加载来自客户端本地存储的数据。



如何从服务器重新加载数据?

解决方案

刚刚推送 record.reload()到Ember Data 。这将要求适配器从服务器重新加载数据,并使用新数据更新记录。



限制:




  • 如果已完成加载并且尚未修改,则只能在记录上调用 reload()。否则,返回的数据将与修改后的数据冲突。在将来,我们将添加一个合并钩子的支持来解决这些冲突,这将允许在更多记录状态下的 reload()

  • 如果您调用 reload()并在适配器返回新数据之前更改或保存记录,则出现同样的原因将导致错误。该错误目前看起来像尝试在< Person:ember263:1>处理事件'reloadRecord'而在状态为rootState.loaded.updated.uncommitted。。基本上,这意味着您的记录处于更新但未提交的状态,您不能在加载和未修改状态之外调用 reload()


I'm using the new router and ember data rev 11.

I have a need to force ember-data to re-load data for a record from the server. Using App.MyRecord.find(2) in setInterval function loads the data from the client local store.

How can I reload the data from the server?

解决方案

I just pushed record.reload() to Ember Data. This will ask the adapter to reload the data from the server and update the record with the new data.

Constraints:

  • You can only call reload() on a record if it has completed loading and has not yet been modified. Otherwise, the returned data will conflict with the modified data. In the future, we will add support for a merge hook to address these sorts of conflicts, which will allow reload() in more record states.
  • If you call reload() and change or save the record before the adapter returns the new data, you will get an error for the same reason. The error currently looks something like Attempted to handle event 'reloadRecord' on <Person:ember263:1> while in state rootState.loaded.updated.uncommitted.. Basically, this means that your record was in the "updated but uncommitted" state, and you aren't allowed to call reload() outside of the "loading and unmodified" state.

这篇关于如何重新加载余烬数据记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆