【发布时间】:2014-11-19 05:17:34
【问题描述】:
当我从服务器收到规范化数据时,我经常需要在存储中获取它。 Ember Data 对此具有语义“推送”:
var thing=normalizedThing
controller.store.push("thing",normalizedThing)
如果我需要更新现有记录,我可以使用 update:
var updatedThing=normalizedUpdatedThing
controller.store.push("thing",normalizedUpdatedThing)
但是,我发现即使存储中还没有加载记录,更新也会起作用;即在这种情况下它会像推动一样。但是,如果记录已经存在,则推送不会像更新一样。实际上它会抛出一个错误。所以我的问题是,推送的目的是什么?当希望使用标准化数据添加/更新存储时,我可以安全地调用 update 吗?还是我应该执行以下操作?
var thing=normalizedThing
if(controller.store.getById("thing",normalizedThing.get("id")){
controller.store.update("thing",normalizedThing)
}else{
controller.store.push("thing",normalizedThing)
}
【问题讨论】:
标签: ember.js ember-data