【发布时间】:2015-11-04 03:59:06
【问题描述】:
我有以下应用程序,我在其中循环并显示一些数据。
<div class="thing" ng-repeat="thing in things">
<h1>{{thing.title}}</h1>
<p>{{thing.description}}</p>
<br/>
<div class="child">
<!-- ng-repeat="child in ??? -->
<p>Display child here</p>
</div>
</div>
我的数据:
$scope.things = [{
id: 1,
title: 'First thing',
description: 'This is just a thing',
extra: {
childs: 3 /* the id of the children */
}
}, {
id: 2,
title: 'Second thing',
description: 'This is just a thing',
extra: {}
}, { /* dont displat this object in the ng-repeat="thing in things" */
id: 3,
title: 'Child thing',
description: 'This is a child thing',
extra: {}
}]
我不明白它如何 ng-repeat 只是 THINGS that are NOT CHILDREN 并在 .child div 中显示 ID 为 thing.extra.childs 的元素。
谁能解释我如何做到这一点?
【问题讨论】:
-
好的,我得到了它正在寻找第一个元素 child = 3 的问题是指的是 id=3 的 JSON 对象,您不想重复这一点。你能改进你的 JSON 吗?
-
我同意@joyBlanks,你应该尝试改进你的 JSON 数据结构,这会让事情变得更容易。
-
有什么建议吗?数据来自其他 API,我可以添加 child: { all the data from id:3 } 但我使用的是 API
-
我猜当你收到数据迭代并将子对象移动到额外的键中时。即解决参考。无论如何,角度会迭代,但它会顺利迭代
标签: javascript angularjs architecture