【问题标题】:ng-repeat JSON AngularJSng-repeat JSON AngularJS
【发布时间】:2017-11-01 13:10:06
【问题描述】:

我在琢磨如何访问具有动态名称的 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

如何使用控制器输出类似这个表格的东西?

【问题讨论】:

    标签: javascript angularjs json angularjs-ng-repeat


    【解决方案1】:

    试试这个

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

    【讨论】:

    • 太棒了!像魅力一样工作。谢谢@Hadi
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    相关资源
    最近更新 更多