从ember数据json中删除模型名称
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从ember数据json中删除模型名称相关的知识,希望对你有一定的参考价值。
Ember数据将数据发送到嵌入了型号名称的服务器。
{
"part" {
"name" : "test1",
"quantity" : 12
}
}
我想从响应中删除“part”字段,所以它看起来像:
{
"name" : "test1",
"quantity" : 12
}
我需要这是通用的,所以它适用于我的商店中的任何模型。
好的,我找到了RESTAdapter中的部分。
serializeIntoHash: function(data, type, record, options) {
var root = underscore(decamelize(type.typeKey));
data[root] = this.serialize(record, options);
},
我试图删除根部分
serializeIntoHash: function(data, type, record, options) {
data = this.serialize(record, options);
}
但它不起作用,它用{}响应
答案
https://github.com/san650/ember-cli-page-object/issues/153
Ember.merge
已被弃用,请使用Ember.assign
App.ApplicationSerializer = DS.RESTSerializer.extend({
serializeIntoHash: function(hash, type, record, options) {
Ember.assign(hash, this.serialize(record, options));
}
});
另一答案
好吧发现了:https://github.com/emberjs/data/issues/771
App.ApplicationSerializer = DS.RESTSerializer.extend({
serializeIntoHash: function(hash, type, record, options) {
Ember.merge(hash, this.serialize(record, options));
}
});
以上是关于从ember数据json中删除模型名称的主要内容,如果未能解决你的问题,请参考以下文章