因此,我从 Controller 中获得了以下对象,该对象具有名称、bean 列表和操作列表:
{
"name": "Charge",
"beans": [
],
"operations": [
{
"name": "getSize",
"returnType": "java.lang.Integer",
"description": "empty description",
"parameters": [
]
},
{
"name": "truncate",
"returnType": "java.lang.Void",
"description": "empty description",
"parameters": [
]
},
{
"name": "count",
"returnType": "java.lang.Integer",
"description": "empty description",
"parameters": [
{
"name": "javaCode",
"type": "java.lang.String",
"value": null
}
]
},
{
"name": "update",
"returnType": "java.lang.Integer",
"description": "empty description",
"parameters": [
{
"name": "javaSelectCode",
"type": "java.lang.String",
"value": null
},
{
"name": "javaUpdateCode",
"type": "java.lang.String",
"value": null
}
]
},
{
"name": "delete",
"returnType": "java.lang.Integer",
"description": "empty description",
"parameters": [
{
"name": "javaCode",
"type": "java.lang.String",
"value": null
}
]
},
{
"name": "dump",
"returnType": "java.lang.Void",
"description": "empty description",
"parameters": [
{
"name": "javaSelectCode",
"type": "java.lang.String",
"value": null
},
{
"name": "destinationPath",
"type": "java.lang.String",
"value": null
}
]
},
{
"name": "select",
"returnType": "java.lang.String",
"description": "empty description",
"parameters": [
{
"name": "javaCode",
"type": "java.lang.String",
"value": null
}
]
}
],
"$$hashKey": "object:620"
}
基本上我想在下拉菜单中显示该对象的所有操作。
所以我想有这样的东西:
<div ng-repeat="operation in object.operations">
{{operation.name}}
</div>
除了上面的代码不在屏幕上显示任何内容,控制台中没有错误,什么也没有。
任何帮助将不胜感激!
编辑:
Javascript 服务:
app.controller('selectAll', ['$http', '$scope' , '$rootScope', function ($http, $scope, $rootScope) {
$scope.response;
$scope.operations;
$rootScope.$on("invokeSelectAll", function(){
$scope.invokeSelectAll();
});
$scope.invokeSelectAll = function(){
$scope.response = $http.post('/invoke/selectAll/', $rootScope.dataObj);
$scope.object = JSON.stringify($rootScope.object);
console.log(" object operation from selectAll " + $scope.object);
$scope.response.then(function(data) {
$scope.responses = data.data ? data.data : "Select Operation not supported on this bean";
});
}
}]);
开发控制台截图: /image/Eblww.jpg
最佳答案
使用 JSON.stringify()
从 JavaScript 对象创建 JSON 字符串。
使用 JSON.parse()
将 JSON 字符串解析为 JavaScript 对象。
在您的情况下,您需要使用 JSON.parse()
因为您从服务器获取 JSON 字符串并希望将其解析为 JavaScript 对象。
$scope.object = JSON.parse($rootScope.object);
关于javascript - 从json中提取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46049655/