這裏是你期望的樣本,純粹的Angular,沒有額外的JavaScript。 我已經添加了一些交易到交易陣列和許多不同的txn,我認爲這是交易編號。
的index.html
<!doctype html>
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="script.js"></script>
<style>
strong {cursor: pointer;}
</style>
</head>
<body>
<div ng-controller="ExampleController">
<ul>
<li ng-repeat="t in data.transactions">
<ul>
<li ng-repeat="(key, value) in t" ng-if="key!='__opened'">
<strong ng-click="t.__opened=!t.__opened">{{key}} --</strong>
<ul ng-if="t.__opened">
<li>
<strong ng-click="value.request.__opened=!value.request.__opened">--Request</strong>
<ul ng-if="value.request.__opened">
<li ng-repeat="re in value.request">
{{re.Field}} {{re.length}} {{re.value}}
</li>
</ul>
</li>
<li>
<strong ng-click="value.response.__opened=!value.response.__opened">--Response</strong>
<ul ng-if="value.response.__opened">
<li ng-repeat="re in value.response">
{{re.Field}} {{re.length}} {{re.value}}
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
的script.js
angular.module('app', []);
angular.module('app')
.controller('ExampleController', ['$scope', function($scope) {
$scope.data = {
"transactions": [{
"ABC-123": {
"request": [{
"Field": "000",
"length": "004",
"value": "0100"
},
{
"Field": "005",
"length": "016",
"value": "11110010 00111100 "
}
],
"response": [{
"Field": "000",
"length": "004",
"value": "0110"
},
{
"Field": "001",
"length": "008",
"value": "00110010"
}
]
},
"DEF-456": {
"request": [{
"Field": "111",
"length": "006",
"value": "0145"
},
{
"Field": "555",
"length": "036",
"value": "22210010 00111100 "
}
],
"response": [{
"Field": "333",
"length": "765",
"value": "5112"
},
{
"Field": "088",
"length": "009",
"value": "00220022"
}
]
}
}, {
"GHI-123": {
"request": [{
"Field": "000",
"length": "004",
"value": "0100"
},
{
"Field": "005",
"length": "016",
"value": "11110010 00111100 "
}
],
"response": [{
"Field": "000",
"length": "004",
"value": "0110"
},
{
"Field": "001",
"length": "008",
"value": "00110010"
}
]
},
"JKF-456": {
"request": [{
"Field": "111",
"length": "006",
"value": "0145"
},
{
"Field": "555",
"length": "036",
"value": "22210010 00111100 "
}
],
"response": [{
"Field": "333",
"length": "765",
"value": "5112"
},
{
"Field": "088",
"length": "009",
"value": "00220022"
}
]
}
}]
}
}]);
和工作plunker一起玩:https://plnkr.co/edit/mokM1ILRY8HbF7BAVa5R?p=preview
希望它能幫助!
這是一個樹形結構,我爲javascript UI樹google搜索,許多合適的組件之一是[jstree](https://www.jstree.com/) – James
不知道爲什麼投票 –
我沒有downvote,但我懷疑這是因爲SO實際上並不是一個「爲我寫代碼」的網站,而更像是「這裏有一些我幾乎可以工作的代碼,但我無法弄清楚這一點」網站。 – Lex