1
我的REST服务器返回从/blog
如下:angularjs资源查询曲解阵列
["hello","yo"]
这是我整个angularjs应用:
var myapp = new angular.module("myapp", ["ngResource"]);
myapp.controller("MainCtl", ["$scope", "$resource", function($scope, $resource){
var Blog = $resource("/blog/:entry", {entry: '@entry'});
$scope.entries = Blog.query();
}]);
当我把{{entries}}
某处HTML,我看这个:[{"0":"h","1":"e","2":"l","3":"l","4":"o"},{"0":"y","1":"o"}]
不知何故angular会误解这个数组值。我也尝试过,结果完全相同:
myapp.controller("MainCtl", ["$scope", "$resource", function($scope, $resource){
var Blog = $resource("/blog/:entry", {entry: '@entry'}, {
list: {
url: "/blog",
method: "GET",
isArray: true,
transformResponse: function(data, headers) {
var h = ["hello","yo"];
console.log(h);
return h;
}
}
});
$scope.entries = Blog.list();
}]);
有趣的是,console.log
调用会打印出正确的值。
顺便说一下这是1.2.10的角度。 – Jake
这很可能是您从服务器端发送响应的方式。你在那里用什么?例如, –
http://pastebin.com/kZJkRp0C – Jake