简体   繁体   English

Angular JS通过无序列表中的2个数组重复

[英]Angular JS Repeating through 2 Arrays In Unordered List

I got this html: 我得到这个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>

Projects and descriptions are Arrays in my Controller. 项目和描述是我控制器中的数组。 Now I'm getting for each item in my Project Array a listitem, but how can I iterate the description as well? 现在,我为项目数组中的每个项目获得了一个列表项,但是如何也可以迭代该描述呢?

Like in the first Iteration: 像第一个迭代一样:

<span>{{descriptions[0]}}</span>

And in the next Iteration for the next p in Projects: 在项目的下一个p的下一个迭代中:

<span>{{descriptions[1]}}</span>

Thanks in regard! 谢谢!

Use track by in ng-repeat 在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM