从ember数据json中删除模型名称

jax*_*jax 4 ember.js ember-data

Ember数据将数据发送到嵌入了型号名称的服务器.

{
    "part" {
       "name" : "test1",
       "quantity" : 12
    }
}
Run Code Online (Sandbox Code Playgroud)

我想从响应中删除"part"字段,所以它看起来像:

{
   "name" : "test1",
   "quantity" : 12
}
Run Code Online (Sandbox Code Playgroud)

我需要这是通用的,所以它适用于我的商店中的任何模型.


好的,我找到了RESTAdapter中的部分.

  serializeIntoHash: function(data, type, record, options) {
    var root = underscore(decamelize(type.typeKey));
    data[root] = this.serialize(record, options);
  },
Run Code Online (Sandbox Code Playgroud)

我试图删除根部分

serializeIntoHash: function(data, type, record, options) {
    data = this.serialize(record, options);
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,它用{}响应

jax*_*jax 8

好的找到了它: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));
  }
});
Run Code Online (Sandbox Code Playgroud)