本文介绍了用ng-repeat同时循环多个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在AngularJs中只使用一个 ng-repeat
来同时遍历两个数组吗?如果是这样,那么如何?
例如,我有两个数组
array1 = [1,2,3,4,5]
array2 = [6,7,8,9,10]
它应该能够为这两个数组产生相同的索引。
解决方案如果您想访问第一个索引的第二个数组,请尝试以下操作:
$ scope.arr1 = [1,2,3,4,5]
$ scope.arr2 = [6,7,8,9,10]
Number1 from array1 = {{number}}
Number2 from array2 = {{arr2 [$ index]}}
看到这个小提琴:
Can I traverse two arrays simultaneously using only one ng-repeat
in AngularJs? If so, then how?
For example I have two arrays
array1 = [1,2,3,4,5]
array2 = [6,7,8,9,10]
It should be able to produce the same index for both the arrays.
解决方案
If you want to acces the second array with the index of the first, try this:
$scope.arr1 = [1, 2, 3, 4, 5]
$scope.arr2 = [6, 7, 8, 9, 10]
<div ng-repeat="number in arr1">
Number from array1 = {{number}}
Number from array2 = {{arr2[$index]}}
</div>
See this fiddle: http://jsfiddle.net/dm9zhgx9/
这篇关于用ng-repeat同时循环多个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!