Javascript 如何将两个js列表映射到一个成对列表?
我有两个相同长度的列表 我想使用angular js创建一个重复的ui表Javascript 如何将两个js列表映射到一个成对列表?,javascript,arrays,angularjs,Javascript,Arrays,Angularjs,我有两个相同长度的列表 我想使用angular js创建一个重复的ui表 <tr ng-repeat="pair in pairs ..> 我该怎么做 将两个列表连接起来,然后以角度重复?或者进行双重重复?您可以使用迭代器中的“$index”从另一个数组中获取值 //controller $scope.pairs = [1, 2, 3]; $scope.otherArray = ['a', 'b', 'c']; //template <tr ng-repeat="pair
<tr ng-repeat="pair in pairs ..>
我该怎么做
将两个列表连接起来,然后以角度重复?或者进行双重重复?您可以使用迭代器中的“$index”从另一个数组中获取值
//controller
$scope.pairs = [1, 2, 3];
$scope.otherArray = ['a', 'b', 'c'];
//template
<tr ng-repeat="pair in pairs">
<td>{{ pair }}</td>
<td>{{ otherArray[$index] }}</td>
</tr>
//控制器
$scope.pairs=[1,2,3];
$scope.otherArray=['a','b','c'];
//模板
{{pair}}
{{otherArray[$index]}
这将适用于长度相同的数组(这是您必须假设的)。您可以使用迭代器中的“$index”从另一个数组中获取值
//controller
$scope.pairs = [1, 2, 3];
$scope.otherArray = ['a', 'b', 'c'];
//template
<tr ng-repeat="pair in pairs">
<td>{{ pair }}</td>
<td>{{ otherArray[$index] }}</td>
</tr>
//控制器
$scope.pairs=[1,2,3];
$scope.otherArray=['a','b','c'];
//模板
{{pair}}
{{otherArray[$index]}
这将使数组的长度相同(这是您必须假设的)
list1
上的ng repeat
{{}
)打印其元素$index
作为索引从另一个数组中获取值angular.module('app',[]).controller('ctrl',function($scope){
$scope.list1=[1,2,3,4];
$scope.list2=[“a”、“b”、“c”、“d”];
})
{{list}}行:{{list}{{{list2[$index]}
list1
上的ng repeat
{{}
)打印其元素$index
作为索引从另一个数组中获取值angular.module('app',[]).controller('ctrl',function($scope){
$scope.list1=[1,2,3,4];
$scope.list2=[“a”、“b”、“c”、“d”];
})
{{list}}行:{{list}{{{list2[$index]}
最好的方法是将两个阵列合并为一个,例如:
var $scope.pairs = [] ;
for (var i = 0 ; i < Array_1.length ; i++) {
$scope.pairs.push( {number: Array_1[i] ,
letter: Array_2[i] } ;
}
var$scope.pairs=[];
对于(var i=0;i
以及您的html:
<tr ng-repeat="pair in pairs>
<td>
{{pair.number}} - {{pair.letter}}
</tr>
</tr>
最好的方法是将两个数组合并为一个,例如:
var $scope.pairs = [] ;
for (var i = 0 ; i < Array_1.length ; i++) {
$scope.pairs.push( {number: Array_1[i] ,
letter: Array_2[i] } ;
}
var$scope.pairs=[];
对于(var i=0;i
以及您的html:
<tr ng-repeat="pair in pairs>
<td>
{{pair.number}} - {{pair.letter}}
</tr>
</tr>
请更详细地阐述你的问题。考虑到这两个数组,你想要的输出是什么?对不起,忘记了。添加了这些列表是否始终具有相同的长度@EladBenda?是的。我这样设置请更详细地阐述你的问题。考虑到这两个数组,你想要的输出是什么?对不起,忘记了。添加了这些列表是否始终具有相同的长度@E拉本达?是的,我就是这么定的