简体   繁体   English

ng-repeat JSON AngularJS

[英]ng-repeat JSON AngularJS

I was woundering how i can access JSON that has dynamic names: 我很讨厌如何访问具有动态名称的JSON:

AngularJS http-get: AngularJS http-get:

.then(function (response) {
                    $scope.GTMcontainersAccount = response.data;
                    console.log($scope.GTMcontainersAccount);

Response JSON: 响应JSON:

{
    "Account2": [{
        "accountId": "*******",
        "containerId": "*******",
        "name": "Container23"
    }, {
        "accountId": "*******",
        "containerId": "*******",
        "name": "Container2"
    }],
    "Account 1": [{
        "accountId": "*******",
        "containerId": "*******",
        "name": "Container1"
    }]
}

My goal here is to use ng-repeat in a table to show like this: 我的目标是在表格中使用ng-repeat来显示如下内容:

AccountName | AccountId | containerId | name
  Account2  |  *******  |   *******   | Container23
  Account2  |  *******  |   *******   | Container2
  Account1  |  *******  |   *******   | Container1

How can use the controller to output something like this table? 如何使用控制器输出类似此表的内容?

Try like to this 尝试这样

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM