角nsResource创建字符数组的REST的字符串数组的数组 [英] Angular nsResource creates an array of char arrays for REST string arrays

查看:136
本文介绍了角nsResource创建字符数组的REST的字符串数组的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有担任了一个Web服务控制器活动的数据。

I have a web service controller that serves up "activity" data

GET /api/activity/list
GET /api/activity/1
GET /api/activity/activity-slug-name
PUT /api/activity
DELETE /api/activity/1

它也提供了一些元的数据。

It also serves up some "meta" data

GET /api/activity/meta/dates
GET /api/activity/meta/states

他们都工作得非常好使用ngResource因为它们都返回JSON对象。
然而,/ API /活动/元/日期不在

They all work extremely well using ngResource as they all return JSON objects. However the /api/activity/meta/dates does not

它返回一个字符串数组

[
    "2013-06-02T17:05:16Z",
    "2013-06-07T17:05:16Z",
    "2013-08-17T17:05:16Z"
]

ngResource变成这个成char数组的数组
请参见:<一href=\"http://stackoverflow.com/questions/16343908/invalid-result-from-ngresource-request-with-string-array\">Invalid从字符串数组ngResource请求结果

显然,我可以拆分元函数了某种形式的ActivityMetaService,但我会preFER,以保持它一起

Obviously i could just split the meta functions out into some form of ActivityMetaService but i would prefer to keep it all together

我的问题是

有没有一种方法来执行此过分热心的对象分解停止ngResource?

Is there a way to stop ngResource from performing this overzealous object decomposition?

或者我应该RAIS一个bug具有角?

Or should i rais a bug with angular?

在此先感谢

*更新*

感谢马克的评论。如果你已经把它作为一个答案,我会接受它,因为它指向角和其他两个答案不与当前的体系结构适合的错误。

Thanks Mark for your comment. If you had placed it as an answer I would have accepted it, because it points to a bug in Angular and the other two answers do not fit with the current architecture.

当你正确的技术,没有人虽然字符串作为80年代中期以来字符数组,C / C ++程序员旁白:)

While you are technical correct, no one has though of Strings as an array of chars since the mid 80s, C/C++ programmers aside :)

我提出一票在GitHub上的angular.js项目,下面

I have raised a ticket on github with the angular.js project, reference below

<一个href=\"https://github.com/angular/angular.js/issues/2664\">https://github.com/angular/angular.js/issues/2664

推荐答案

我们的,你可以尝试使用transformRequest

Our you could try to use the transformRequest

query: {
  method: 'GET',
  isArray: true,
  transformResponse: function (data, headers) {
    var tranformed = [];
    [].forEach.call(eval(data), function (d) {
        tranformed.push({ name: d });
    });
    return tranformed;
  }

}

这篇关于角nsResource创建字符数组的REST的字符串数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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