[英]AngularJS Nested ng-repeat and ng-if on JSON file
I'm trying to figure out how to iterate through a JSON file and grab the children of a particular data item. 我正在尝试找出如何遍历JSON文件并获取特定数据项的子级的方法。 I know this is going to require the use of nested ng-repeaters, as I am using angularJS, but I can't seem to get it to output anything. 我知道这将需要使用嵌套的ng-repeaters,就像我在使用angularJS一样,但是我似乎无法得到它来输出任何东西。 Any ideas? 有任何想法吗?
Note: I use an ng-if to only take in the children of the id "someIdPassedIn". 注意:我使用ng-if只接受ID为“ someIdPassedIn”的子代。
My HTML: 我的HTML:
<span ng-repeat="item in dataItems">
<span ng-if="item.id == someIdPassedIn">
<span ng-repeat="child in item.children">
{{ child.id }}
</span>
</span>
</span>
My JSON file: 我的JSON文件:
[
{
"id": 1,
"name": "test1",
"children": [
{
"id": 1,
"name": "child"
}
]
},
{
"id": 2,
"name": "test2",
"children": [
{
"id": 1,
"name": "child"
}
]
},
{
"id": 3,
"name": "test3",
"children": [
{
"id": 1,
"name": "child"
}
]
}
]
With the limited amount of information available, it appears as though the property names in your template are incorrect. 在可用信息量有限的情况下,似乎模板中的属性名称不正确。 I took a shot at fixing them, maybe it will point you in the right direction if it's not quite perfect. 我尝试修复它们,如果它不是很完美的话,也许会为您指明正确的方向。
<span ng-repeat="item in dataItems">
<span ng-if="item.id == someIdPassedIn">
<span ng-repeat="child in item.children">
{{ child.id }}
</span>
</span>
</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.