我正在使用
DEBUG: -------------------------------
DEBUG: Ember : 1.12.1
DEBUG: Ember Data : 1.13.4
DEBUG: jQuery : 2.1.4
DEBUG: -------------------------------
我的服务器API仅使用更新对象的ID回复PUT请求,此响应示例为:
{
data:[123],
meta{total:1},
errors:[]
}
如何更改ember-data配置以允许这样的对象? AFAIK ember-data期望响应中的整个发送对象。 感谢
import DS from "ember-data";
export default DS.Store.extend({
/**
* @tampered _super
* @param internalModel
* @param dataArg
*/
didSaveRecord: function (internalModel, dataArg) {
var data;
if (dataArg && dataArg.data && dataArg.data.id && dataArg.data.id !== 'undefined' && Ember.typeOf(dataArg.data.id) !== 'undefined') {
data = dataArg.data;
}
if (data) {
// normalize relationship IDs into records
this._backburner.schedule("normalizeRelationships", this, "_setupRelationships", internalModel, internalModel.type, data);
this.updateId(internalModel, data);
}
//We first make sure the primary data has been updated
//TODO try to move notification to the user to the end of the runloop
internalModel.adapterDidCommit(data);
},
});
答案 0 :(得分:0)
您使用的是什么序列化程序?使用JSON API,您可以尝试以下方式:
export default DS.JSONAPISerializer.extend({
normalizeUpdateRecordResponse(store, clazz, payload) {
payload.data = {
id: payload.data[0]
}
return payload;
}
})
这里有更多信息:http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html