ember data REST change JSON

笑着哭i 提交于 2019-12-10 16:38:55

问题


I am using ember-data 1.0.0-beta.4. On update it sends PUT request with following JSON

{"property": { "name":"name", "age":"22" } }

How can change my RESTAdapter to send following JSON instead of above

{ "name":"name", "age":"22" }

Please help

Thanks


回答1:


create a custom serializer and override the serializeIntoHash hook, something like this should do it (I didn't test this).

Read more about serializers here: 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];
      }
    }
  }
});


来源:https://stackoverflow.com/questions/21074041/ember-data-rest-change-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!