Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  1] [ 3]  / answers: 1 / hits: 16476  / 11 Years ago, sun, may 5, 2013, 12:00:00

I like the way the query() method returns an array of resources, which can be saved to the server again.

I am trying to use Angular against the Drupal RestWS module, which returns an object with several meta properties and a property called list where the actual data are stored. Is there please a way of telling the resource to take that array instead ?



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

More From » angularjs

 Answers
49

With the latest Angular version (1.1.2 or later), you can configure the resource with a 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
}
}
);

[#78419] Friday, May 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckenna

Total Points: 445
Total Questions: 109
Total Answers: 109

Location: Virgin Islands (U.S.)
Member since Sun, May 16, 2021
3 Years ago
;