ember data serializer data mapping

前端 未结 1 1763
一生所求
一生所求 2021-01-06 16:16

I\'m using ember & ember-data to try and consume a json feed from the server. Here is my code:

App = Ember.Application.create();

DS.RESTAdapter.configur         


        
相关标签:
1条回答
  • 2021-01-06 17:05

    You have 2 options

    • make your server compatible, and let it returns the json as ember data expects it,
    • write your own adapter/serializer to support this format.

    UPDATE: write your own serializer UPDATE 2: get rid of unused functions

    https://github.com/emberjs/data/blob/master/packages/ember-data/lib/serializers/json_serializer.js#L196

    You can inherit from the DS.RESTSerializer and change extract with this code

      extract: function(loader, json, type, record) {
        var root = 'data';
    
        if (json[root]) {
          if (record) { loader.updateId(record, json[root]); }
          this.extractRecordRepresentation(loader, type, json[root]);
        }
      }
    

    This assumes that the content of request will always be under the data key of your json.

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