How to reload an ember data record?

前端 未结 1 881
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 14:28

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

相关标签:
1条回答
  • 2020-12-08 15:13

    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.
    0 讨论(0)
提交回复
热议问题