角$资源阵列中的数据错误 [英] Angular $resource array data error

查看:69
本文介绍了角$资源阵列中的数据错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON格式的服务器响应阵列数据:

Server response an array data in JSON format:

["2345","1234"]

角服务模块定义:

Angular service module define:

angular.module('MySource', ['ngResource']).factory('Phone', function($resource){
  return $resource('/api/source');
});

然后我用 Phone.query(); 来获取数组数据,但得到这个:

Then I use Phone.query(); to fetch array data, but got this:

[{"0":"2","1":"3","2":"4","3":"5"},{"0":"1","1":"2","2":"3","3":"4"}]

$ HTTP

$http.get('/inner/source').success(function(data){
  // data = ["2345", "1234"]
});

这是什么问题?为什么 $资源拆分阵列?请问我用 $资源错了?

What's the problem? Why $resource split the array? Does I use $resource wrong way?

感谢。

推荐答案

$资源要求的响应是对象或对象数组。要么改变你的回应是这样的:

$resource requires the response to be objects, or array of objects. Either change your response to something like this:

[{"value":"2345"},{"value":"1234"}]

$ HTTP 服务

这篇关于角$资源阵列中的数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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