Chr*_*nke 6 javascript indexing angularjs
我似乎无法理解这个小问题:
<ul ng-repeat="parent in parents">
<li>Mother: <i>{{parent.mother}}</i></li>
<li>Father: <i>{{parent.father}}</i></li>
<a href="#" ng-click="showKids()">Show Kids</a>
<ul ng-repeat="kid in parent.kids" ng-show="active">
<li>{{kid.name}}</li>
</ul>
</ul>
Run Code Online (Sandbox Code Playgroud)
当我点击"显示孩子"时,我只想展示我点击的父母的孩子,而不是另一个.所以我需要某种索引,我在ng-show中使用的模型只针对特定元素.
由于$ scope.parents来自后端服务器并且使用ng-init加载,我不知道如何在控制器写入列表之前访问它以添加"活动"元素.
odi*_*seo 11
您可以设置迭代器索引ng-repeat="parent in parents"并使用它来使用两个函数:showKids(index)当您单击子项列表时,将标记父项列表应该处于活动状态,并且isShowing(index)为了知道您应该显示哪些子列表ng-show
我根据我的想法重写了你的代码http://jsfiddle.net/odiseo/twSFK/7/
| 归档时间: |
|
| 查看次数: |
9140 次 |
| 最近记录: |