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
服务