Angularjs resource query () an array of results as a property

I like the way the query() method returns an array of resources that can be stored on the server again.
I am trying to use Angular for the Drupal RestWS module , which returns an object with several "meta" properties and a property called a list, where the actual data is stored. Is there any way to tell the resource to take this array?

Example: GET author.json returns:

 first: "http://dgh/author?page=0" last: "http://dgh/author?page=0" list: [{id:1, type:author, uid:{uri:http://dgh/user/1, id:1, resource:user}, created:1367770006,…},…] self: "http://dgh/author" 
+12
javascript angularjs angular-resource
May 05 '13 at 17:35
source share
1 answer

In the latest version of Angular (1.1.2 or later), you can configure the resource using transformResponse:

 var MyResource = $resource( '/author.js', {}, { 'get': { method: 'GET', transformResponse: function (data) {return angular.fromJson(data).list}, isArray: true //since your list property is an array } } ); 
+20
May 05 '13 at 17:45
source share



All Articles