我有两个数组对象(数组A和数组B),我正在构建基于此的单个角度表。 首先,我需要迭代数组A并填充几列,其他列基于数组B. 我从数组A中获取密钥并传递密钥以从数组B中获取值。
请让我知道如何以角度实现这一目标?
<tbody>
<tr ng-repeat="a in arrayA">
<td> <b>{{$index+1}}</b> </td>
<td> <b>{{a.id}}</b> </td>
<td> <b>{{a.name}}</b> </td>
<td> {{a.number}} </td>
<td> This value should be from arrayB . I will pass the key a.id and here i need to iterate arrayB and get corresponding value from arrayB</td>
<td> This value should be from arrayB . I will pass the key a.id and here i need to iterate arrayB and get corresponding value from arrayB</td>
</tr>
</tbody>
答案 0 :(得分:2)
试试这个
控制器
$scope.getValue = function (id) {
var returnData = '';
angular.forEach(arrayB,function(index){
if (index.id == id) {
returnData = index.name;
}
})
return returnData
}
HTML
<tbody>
<tr ng-repeat="a in arrayA">
<td> <b>{{$index+1}}</b> </td>
<td> <b>{{a.id}}</b> </td>
<td> <b>{{a.name}}</b> </td>
<td> {{a.number}} </td>
<td> {{getValue(a.id)}} This value should be from arrayB . I will pass the key a.id and here i need to iterate arrayB and get corresponding value from arrayB</td>
<td> This value should be from arrayB . I will pass the key a.id and here i need to iterate arrayB and get corresponding value from arrayB</td>
</tr>
</tbody>