Ember REST change JSON data

I am using ember-data 1.0.0-beta.4. When updating, it sends a PUT request with the following JSON

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

How to change my RESTAdapter to send the next JSON instead of above

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

Please, help

thanks

+4
source share
1 answer

create your own serializer and redefine the hook serializeIntoHash, something like this should do it (I have not tested 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];
      }
    }
  }
});
+2

All Articles