我有两个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中的信息显示为一个表格,其中" name"来自JSON 1的作为列分隔符(例如|" id" |" article" |" publisher" |)
我知道要获得JSON 1的名称功能,我可以很容易地做到
<tr ng-repeat="item in tableInfo">
<td>{{item.name}}</td>
</tr>
但是如何访问JSON 2中每个元素的每个属性(item.name)?
答案 0 :(得分:0)
<!-- item.name comes from the parent loop -->
<td ng-repeat="anotherItem in currentInfo">
{{anotherItem[item.name]}}
</td>