簡體   English   中英

Angular JS通過無序列表中的2個數組重復

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM