所以我在我的JSON文件中有这个:
[{
"title": "Secondary Containment",
"products": {
"product": [
{
"id": "1001",
"name": "one"
},
{
"id": "1002",
"name": "two"
},
{
"id": "1003",
"name": "three"
}
]
}
}, {
"title": "Another Title",
"products": {
"product": [
{
"id": "1011",
"name": "alpha"
},
{
"id": "1012",
"name": "beta"
},
{
"id": "1013",
"name": "gamma"
}
]
}
}]
我会在ng-repeat中包含哪些内容来重复列表中产品的ID?
我的外部容器中有ng-repeat =“类别中的类别”,它重复不同的标题{{category.title}}但是它不重复内部数组,当我尝试输出{{category。 products.product.id}}
有什么想法吗?
答案 0 :(得分:2)
您需要嵌套ng-repeat
<div ng-repeat="category in categories">
<div ng-repeat="product in category.products.product">
{{product.id}}
</div>
</div>
答案 1 :(得分:1)
你的HTML应该是
<div data-ng-repeat="category in categories">
<div data-ng-repeat="product in category.products.product">
{{product.id}}
</div>
</div>
你可以像尼克希尔那样说。但是你需要嵌套ng-repeat
。但我个人建议使用data-ng-repeat
代替ng-repeat
。使用data-ng-*
的唯一主要原因是 The data-ng-* allows the HTML to be validated through validators that do not understand Angular