【发布时间】:2015-06-03 10:10:09
【问题描述】:
我正在开发一个 angularJS 应用程序,我在其中访问服务并获取 JSON 数据,如下所示。
{
"repositoryFileDto":[
{ "aclNode":"false",
"createdDate":"1433166794593",
"fileSize":"16208",
"folder":"false",
"hidden":"false",
"id":"d4850a7e-17f7-4ee6-a3c5-125c26077da8",
"lastModifiedDate":"1433166794593",
"locale":"en",
"localePropertiesMapEntries":[ ],
"locked":"false",
"name":"accountInfo.prpt",
"ownerType":"-1",
"path":"/home/admin/accountInfo.prpt",
"title":"accountInfo",
"versionId":"1.0",
"versioned":"true" },
{ },
{ },
{ }
]
}
从上面的数组中,我需要获取每个对象的名称属性并将它们推送到一个列表中。
这是我的代码,但它说 undefined 不是函数。
$scope.filteredDashboards = [];
$scope.ExistingreportDetails = [];
$scope.GetReportDetails = function() {
$http({
method: 'GET',
url: 'http://192.168.1.201/api/repo/files/%3Ahome%3Aadmin/children?showHidden=false&filter=*',
// cache: $templateCache,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With',
'Authorization': 'Basic YWRtaW46cGFzc3dvcmQ='
}
}).
success(function(data, status) {
$scope.ExistingreportDetails = angular.toJson(data);
$scope.filteredDashboards =$scope.ExistingreportDetails[0].repositoryFileDto ;
console.log($scope.ExistingreportDetails);
$scope.filteredDashboards.forEach(function(entry) {
console.log(entry);
});
$scope.ExistingreportDetails = $scope.ExistingreportDetails["1"].widgets;
//alert("success");
}).
error(function(data, status) {
alert("Request failed");
});
};
我需要这样的输出,
$scope.reports =
[
{
name: "AODdetails",
title: "#f00"
},
{
name: "AccountInfo",
title: "#0f0"
}
]
【问题讨论】:
-
调试您的代码并尝试识别未定义的函数。
-
您上面的 json 中的颜色和值字段在哪里??
-
不是颜色和价值,这是我的错误。实际姓名和头衔
标签: json angularjs http controller