Transform JSON to an appropriate format for RESTAdapter EmberJS

后端 未结 4 683
Happy的楠姐
Happy的楠姐 2020-12-18 06:20

I receive a JSON from our API that has the following format

[
  {
    \"id\": 45,
    \"name\": \"Pasta\",
    \"_order\": 0,
    \"is_hidden\": null,
    \         


        
4条回答
  •  执念已碎
    2020-12-18 06:35

    In general, you'll probably want to implement a couple of methods in your serializer if you have to tweak your JSON:

    App.ApplicationSerializer = DS.RESTSerializer.extend({
        normalize: function(type, hash, prop) {
            // change your incoming JSON to ember-style here
        },
        serialize: function(record, options) {
            // change your outgoing ember-data record to your server's JSON here
        }
    });
    

    EDIT: You may also in your case need to override extractArray as well: http://emberjs.com/api/data/classes/DS.RESTSerializer.html#method_extractArray

提交回复
热议问题