目前,我正在尝试使用angularJS中的forEach方法映射2个对象,并在手风琴中显示它们。我并没有真正得到我想要的结果……它并没有真正过滤或吐出我想要的html中的正确数据。
HTML:
<accordion ng-repeat="fee in fees">
<accordion-group ng-if="fee.feeBag.length">
<accordion-heading>
{{fee.headingName}}
</accordion-heading>
<div class="feecode-height" ng-repeat="feeParameter in fee.feeBag">
<div class="row">
<div class="col-xs-1">{{feeParameter.name}}</div>
<div class="col-xs-4">{{feeParameter.text}}</div>
<div class="col-xs-2" >{{feeParameter.amount}}</div>
</div>
</div>
</accordion-group>
</accordion>
控制器:
angular.forEach($scope.fees, function(value, key) {
angular.forEach(value.feeBag, function(value2, key2) {
if (value.feeBag[key2].name === $scope.otherFees.name) {
value.feeBag[key2].text = $scope.otherFees.text;
value.feeBag[key2].amount = $scope.otherFees.amount;
return value.feeBag[key2];
} else {
// remove the ones that dont belong
// value.feeBag.splice(key, 1);
}
});
});
JSON值:
$scope.otherFees = [{'name': 1, 'text': 'ok', 'amount': 2}, {'name': 2, 'text': 'hello', 'amount': 3}, {'name': 3, 'text': 'cool', 'amount': 3}]
$scope.fees = [
{
'headingName': 'firstHeader',
'feeBag': [
{'name': 1}
]
},
{
'headingName': 'secondHeader',
'feeBag': [
{'name': 2}
]
},
{
'headingName': 'thirdHeader',
'feeBag': [
{'name': 3}
]
}
]
感谢所有帮助:D