【问题标题】:ember data REST change JSONember 数据 REST 更改 JSON
【发布时间】:2014-01-12 11:24:54
【问题描述】:

我正在使用 ember-data 1.0.0-beta.4。更新时,它使用以下 JSON 发送 PUT 请求

{“属性”:{“名称”:“名称”,“年龄”:“22”}}

如何更改我的 RESTAdapter 以发送以下 JSON 而不是上面的

{ "姓名":"姓名", "年龄":"22" }

请帮忙

谢谢

【问题讨论】:

    标签: json ember.js ember-data


    【解决方案1】:

    创建一个自定义序列化程序并覆盖 serializeIntoHash 钩子,应该这样做(我没有测试这个)。

    在此处阅读有关序列化程序的更多信息:https://github.com/emberjs/data/blob/master/TRANSITION.md

    App.PropertySerializer = DS.RESTSerializer.extend({
      serializeIntoHash: function(data, type, record, options) {
        var root = Ember.String.decamelize(type.typeKey),
            properties = this.serialize(record, options);
        for(var prop in properties){
          if(properties.hasOwnProperty(prop)){
            data[prop] = properties[prop];
          }
        }
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2015-11-13
      • 2014-08-29
      • 1970-01-01
      • 2014-04-24
      • 2012-06-11
      • 2017-01-16
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      相关资源
      最近更新 更多