无法使用ng-repeat访问JSON

Unable to access JSON using ng-repeat

本文关键字:访问 JSON ng-repeat      更新时间:2023-09-26

我有两个JSON对象。一个JSON对象应该为我提供第二个JSON对象的键。JSON 1 (tableInfo):

[
 -{
  name: "id",
  dataType: "Integer",
  isEditable: false
 }
 -{
  name: "article",
  dataType: "String",
  isEditable: true
 }
 -{
  name: "publisher",
  dataType: "String",
  isEditable: false
 }
-{
 name: "metadata.comments",
 dataType: "Integer",
 isEditable: false
 }
]

JSON 2 (currentInfo):

[
-{
 id: 0,
 article: "JavaScript Conquers the World",
 publisher: "Daily Times",
 metadata: {
      comments: 4
     }
 }
-{
 id: 1,
 article: "The Problem with Foobar",
 publisher: "New York Times",
 metadata: {
      comments: 27
     }
 }
]

我想使用一个ng-repeat(或类似的指令)来显示JSON 2中的信息作为一个表,其中JSON 1中的"name"作为列分隔符(例如|"id"|"article"|"publisher"|)

我知道要获取JSON 1的名称特性,我可以很容易地使用

<tr ng-repeat="item in tableInfo">
    <td>{{item.name}}</td>
</tr>

但是如何访问JSON 2中每个元素的每个属性(item.name) ?

<!-- item.name comes from the parent loop -->
<td ng-repeat="anotherItem in currentInfo">
    {{anotherItem[item.name]}}
</td>