如何在包含其他值之中的对象的数组上使用ng-repeat

时间:2018-12-24 08:17:12

标签: angularjs

我有一个包含元素和对象的数组。我需要在html中显示元素以及对象的键和值。

我尝试使用ng-repeat;出现数组元素的值,但不显示对象键和值。

$scope.systemarray = [{'system':'DHX','DB':{'DEV':'DH1','QAS':'QH1'}}]
<tr>
<th scope="col">System</th>
<th scope="col">DB</th>
<th scope="col">Application</th>
</tr>

我想在“系统”标题下显示“ DHX”

“ DB”标题下的DEV和QAS

,并在“应用程序”标题下显示“ DH1”和“ QH1”。

附加信息:“ DEV”是数据库名称,“ DH1”是使用“ DEV”作为数据库的应用程序的名称,QAS和QH1也是如此。我有几个这样的数据库和应用程序,这就是为什么我选择以这种方式创建对象的原因-'DBname':'Appname'。

有几个这样的应用程序,因此,每当我从python程序检索此数据时,我将具有不同的“ DBname”及其对应的“ Appname”。 谢谢您的时间

1 个答案:

答案 0 :(得分:2)

您可以尝试显示系统,数据库和应用程序名称:

<table>
  <thead>
    <tr>
      <th>System</th>
      <th>DB</th>
      <th>Application</th>
    </tr>
  </thead>
  <tbody ng-repeat="system in systemarray">
      <tr ng-repeat="(databaseName, applicationName) in system.DB">
         <td>{{system.system}}</td>
         <td>{{databaseName}}</td>
         <td>{{applicationName}}</td>
      </tr>
  </tbody>
</table>

朋克:http://plnkr.co/edit/YPIj5VEep57jK4YscGoG?p=preview

希望有帮助!