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

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

问题描述

我正在使用新的路由器和 ember data rev 11.

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

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

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?

推荐答案

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

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.

  • 您只能在已完成加载且尚未修改的记录上调用 reload().否则,返回的数据将与修改后的数据发生冲突.将来,我们将添加对合并挂钩的支持以解决此类冲突,这将允许 reload() 处于更多记录状态.
  • 如果您在适配器返回新数据之前调用 reload() 并更改或保存记录,您将因同样的原因收到错误消息.该错误目前看起来类似于 Attempted to handle event 'reloadRecord' on 而处于 rootState.loaded.updated.uncommitted 状态..基本上,这意味着您的记录处于已更新但未提交"状态,并且不允许在加载和未修改"状态之外调用 reload().
  • 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.

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

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