Delete JSON root element for POST/PUT operations in Ember Data

后端 未结 1 451
刺人心
刺人心 2021-02-13 03:09

I\'m consuming a web service that in POST/PUT verbs expects a JSON like this:

{
    \"id\":\"CACTU\",
    \"companyName\": \"Cactus Comidas para llevar\",
    \         


        
1条回答
  •  既然无缘
    2021-02-13 03:34

    You'll want to override one of the serialize methods, I think serializeIntoHash might work:

    App.CustomerSerializer = DS.RESTSerializer.extend({
      serializeIntoHash: function(hash, type, record, options) {
        Ember.merge(hash, this.serialize(record, options));
      }
    });
    

    This is instead of the normal serializeIntoHash which looks like this:

      serializeIntoHash: function(hash, type, record, options) {
        hash[type.typeKey] = this.serialize(record, options);
      }
    

    Additional documentation can be found here:

    https://github.com/emberjs/data/blob/v2.1.0/packages/ember-data/lib/serializers/rest-serializer.js#L595

    0 讨论(0)
提交回复
热议问题