,這是我的代碼,以便訪問嵌套JSON數組,並需要檢索JSON數據如何使用angularjs
這是我的JSON數據的某些部分,在這方面,我需要找回拓撲ID,節點ID,TP-ID這是在嵌套的JSON數組這麼寫一些代碼只是檢查一次,我是很新的angularjs.so幫我出這個問題
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-base64/2.0.5/angular-base64.js"></script>
<body>
<div ng-app="list">
<div ng-controller="ListCtrl">
<ul ng-repeat="data in network-topology">
<li >{{data.topology}}</li>
</ul>
</div>
<div ng-controller="ListCtrl">
<ul ng-repeat="data1 in topology">
<li >{{data1.topology-id}}</li>
</ul>
</div>
<div ng-controller="ListCtrl">
<ul ng-repeat="data2 in node">
<li >{{data2.node-id}}</li>
</ul>
</div>
<div ng-controller="ListCtrl">
<ul ng-repeat="data3 in termination-point">
<li >{{data3.tp-id}}</li>
</ul>
</div>
<script>
var app = angular.module('list', ['base64']);
app.controller('ListCtrl', function($scope, $http, $base64) {
$http.defaults.headers.common = {"Access-Control-Request-Headers": "accept, origin, authorization"};
$http.defaults.headers.common['Authorization'] = 'Basic ' + $base64.encode('admin' + ':' + 'admin');
$http({
method: 'GET',
url: 'http://10.132.32.212:8181/restconf/operational/network-topology:network-topology/',
contentType: 'application/json; charset=utf-8',
}).success(function(tdata) {
\t $scope.network-topology= tdata.network-topology;
\t $scope.topology= tdata.topology;
\t $scope.topology-id = tdata.topology-id;
$scope.node-id = tdata.node-id;
\t $scope.tp-id = tdata.tp-id;
$scope.topology= [];
$scope.node= [];
$scope.termination-point= [];
angular.forEach(tdata.network-topology, function(network-topology, index){
angular.forEach(network-topology.topology, function(topology, index){
\t \t angular.forEach(network-topology.topology.node, function(node, index) {
angular.forEach(network-topology.topology.node.termination-point, function(termination-point, index){
$scope.termination-point.push(termination-point);
});
\t });
});
});
</script>
</body>
</html>
請發表您的JSON數據'tdata' – Nishant123
{ 「網絡拓撲」:{ 「拓撲」: {「topology-id」:「flow:1」, 「node」:[「node-id」:「openflow:1」, 「termination-point」:[ {「tp-id」:「openflow:1:2」, 「opendaylight-topology-inventory:inventory-node-connector-ref」:「/ opendaylight-inventory:nodes –