[英]Angular JS Repeating through 2 Arrays In Unordered List
我得到这个HTML:
<ul class="demo-list-three mdl-list">
<li class="mdl-list__item mdl-list__item--three-line" ng-repeat="p in projects">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-avatar">person</i>
<span>{{p}}</span>
<span class="mdl-list__item-text-body">
{{descriptions[0]}}
</span>
</span>
<span class="mdl-list__item-secondary-content">
<a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a>
</span>
</li>
</ul>
项目和描述是我控制器中的数组。 现在,我为项目数组中的每个项目获得了一个列表项,但是如何也可以迭代该描述呢?
像第一个迭代一样:
<span>{{descriptions[0]}}</span>
在项目的下一个p的下一个迭代中:
<span>{{descriptions[1]}}</span>
谢谢!
在ng-repeat中使用track by
<ul class="demo-list-three mdl-list">
<li class="mdl-list__item mdl-list__item--three-line" ng-repeat="p in projects track by $index">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-avatar">person</i>
<span>{{p}}</span>
<span class="mdl-list__item-text-body">
{{descriptions[$index]}}
</span>
</span>
<span class="mdl-list__item-secondary-content">
<a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a>
</span>
</li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.