Angularjs资源查询()结果数组作为属性 [英] Angularjs resource query() result array as a property

查看:182
本文介绍了Angularjs资源查询()结果数组作为属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢的方式,查询()方法返回的资源数组,可以再保存到服务器上。结果
我试图用对 Drupal的RestWS 模块,它有几个元的属性和属性叫列表,返回一个对象角实际数据被存储。有没有请告诉资源,采取阵列,而不是一个办法吗?

例如: GET author.json 返回:

 第一:HTTP:// DGH /作者页= 0
最后:HTTP:// DGH /作者页= 0
清单:[{ID:1,类型:作者,发表于:{网址:HTTP:// DGH /用户/ 1,ID:1,资源:用户},创建:1367770006,...},...]
自我:HTTP:// DGH /作者


解决方案

通过最新版本的角(1.1.2或更高版本),可以配置一个transformResponse资源:

  VAR MyResource = $资源(
    /author.js',
    {},
    {
        '得到':{
            方法:GET,
            transformResponse:功能(数据){返回angular.fromJson(数据).LIST},
            IsArray的:因为你的列表属性真正//是一个数组
        }
    }
);

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"

解决方案

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
        }
    }
);

这篇关于Angularjs资源查询()结果数组作为属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆