ul li循环中有多个数组

时间:2018-01-31 05:40:18

标签: javascript angularjs html-lists

我想在ul / li中显示数据,所以我通过html中的循环获取它,如:

我有两个数组:

  $mainarray = [{"Name":"data1","count":9},{"Name":"data2","count":10},
 {"Name":"data3","count":4},{"Name":"4","count":20}];


 $color = ['red','pink','green','yellow','black'];
 $color = ['red','pink','green','yellow','black'];

我像这样循环遍历主数组并且工作正常:

<ul style="list-style-type:circle; padding: 0px !important; font-size:22px;">
<li ng-repeat="item in mainarray " style="margin-bottom: 10px;"; >
    <span style=" font-size: 16px; ">{{ item.name }}</span>
</li>
</ul>

但是,我想添加$ color,如:

for data1 -> red
data2->pink 
and so on ....

我尝试过多次循环,但它无效!

任何线索?

1 个答案:

答案 0 :(得分:1)

您可以使用$index

<span style=" font-size: 16px; ">{{ item.name }} -> {{ color[$index] }}</span>