Ember.js REST Adapter without JSON root

后端 未结 5 1309
Happy的楠姐
Happy的楠姐 2020-12-06 18:56

The Ember.js REST Adapter expects the JSON to be returned as:

{
    \"person\": {
        \"first_name\": \"Barack\",
        \"last_name\": \"Obama\",
              


        
5条回答
  •  天涯浪人
    2020-12-06 19:22

    I tried to add root to json. This works for me:

    App.Adapter = DS.RESTAdapter.extend({
        findAll: function(store, type, since) {
            var root, adapter;
                var plural; // Insert this line
            root = this.rootForType(type);
            adapter = this;
                plural = this.pluralize(root); // Insert this line
            return this.ajax(
                    this.buildURL(root), 
                    "GET",
                    {
                        data: this.sinceQuery(since)
                    }).then(function(json) {
                        eval ( "json = {" + plural + " : json }" ); // Insert this line
                        adapter.didFindAll(store, type, json);
                    }).then(null, DS.rejectionHandler);
        }
    });
    

提交回复
热议问题