[英]ng-repeat JSON AngularJS
我很討厭如何訪問具有動態名稱的JSON:
AngularJS http-get:
.then(function (response) {
$scope.GTMcontainersAccount = response.data;
console.log($scope.GTMcontainersAccount);
響應JSON:
{
"Account2": [{
"accountId": "*******",
"containerId": "*******",
"name": "Container23"
}, {
"accountId": "*******",
"containerId": "*******",
"name": "Container2"
}],
"Account 1": [{
"accountId": "*******",
"containerId": "*******",
"name": "Container1"
}]
}
我的目標是在表格中使用ng-repeat來顯示如下內容:
AccountName | AccountId | containerId | name
Account2 | ******* | ******* | Container23
Account2 | ******* | ******* | Container2
Account1 | ******* | ******* | Container1
如何使用控制器輸出類似此表的內容?
嘗試這樣
<table>
<thead>
<tr>
<th>AccountName</th>
<th>AccountId</th>
<th>containerId</th>
<th>name</th>
</tr>
</thead>
<tbody ng-repeat="(k,v) in data">
<tr ng-repeat="(k1,v1) in v">
<td>{{k}}</td>
<td >{{v1.accountId}}</td>
<td >{{v1.containerId}}</td>
<td >{{v1.name}}</td>
</tr>
</tbody>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.