Angularjs资源查询()结果数组作为属性

moj*_*zis 12 javascript angularjs angular-resource

我喜欢该query()方法返回资源数组的方式,可以再次保存到服务器.
我正在尝试使用Angular来对抗Drupal RestWS模块,该模块返回一个具有多个"元"属性的对象和一个名为list的属性,其中存储了实际数据.有没有办法告诉资源采取该阵列?

示例:GET author.json返回:

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"
Run Code Online (Sandbox Code Playgroud)

Ale*_*øld 21

使用最新的Angular版本(1.1.2或更高版本),您可以使用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
        }
    }
);
Run Code Online (Sandbox Code Playgroud)