Below are the specific data sets:
$scope.icons = [{
"id": 1,
"bonuses": [
{ "id": 1, "name": "Rob", "amount": 10, "foreman": 1, "percA": 1, "percB": 0 },
{ "id": 2, "name": "Mark", "amount": 20, "foreman": 1, "percA": 1, "percB": 0 },
]
}, {
"id": 2,
"bonuses": [
{ "id": 1, "name": "Rob", "amount": 11, "foreman": 1, "percA": 1, "percB": 0 },
{ "id": 2, "name": "", "amount": 30, "foreman": 1, "percA": 1, "percB": 0 },
]
}, {
"id": 3,
"bonuses": [
{ "id": 1, "name": "Rob", "amount": 10, "foreman": 1, "percA": 1, "percB": 0 },
{ "id": 2, "name": "Kent", "amount": 35, "foreman": 1, "percA": 1, "percB": 0 },
]
}];
In the controller there is this function:
$scope.getBonusPeople = function() {
var bonusData = [];
angular.forEach($scope.icons, function(item) {
angular.forEach(item.bonuses, function(bonusLine) {
if (bonusData.indexOf(bonusLine) == -1 ) {
bonusData.push(bonusLine);
}
})
});
return $scope.bonusPeople = bonusData;
}
The output of this function is displayed as follows:
Rob - 10
Mark - 20
Rob - 11
- 30
Rob - 10
Kent - 35
The goal is to extract only lines where the 'name' value in bonuses is present.
The desired result should be:
Rob - 10
Mark - 20
Rob - 11
Rob - 10
Kent - 35
How can I accomplish this?
A link to a relevant code sample: http://plnkr.co/edit/wZpr0nerqti4L2Yg37iT?p=preview