【问题标题】:Remove model name from ember data json从 ember 数据 json 中删除模型名称
【发布时间】:2014-07-04 08:43:52
【问题描述】:

Ember 数据将数据发送到嵌入模型名称的服务器。

{
    "part" {
       "name" : "test1",
       "quantity" : 12
    }
}

我希望从响应中删除“部分”字段,使其看起来像:

{
   "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);
}

但它不起作用,它以 {}

响应

【问题讨论】:

    标签: ember.js ember-data


    【解决方案1】:

    好的,找到了: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));
      }
    });
    

    【讨论】:

    【解决方案2】:

    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));
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2015-12-26
      • 2013-02-16
      • 1970-01-01
      • 2013-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多