I need to filter an array of objects by another array of objects, which I am finding more difficult than I thought it would be.
$scope.ArrayMain = [{
"LocationID": 1,
"AdornmentID": 11,
"ApplicabilityID": 111
},{
"LocationID": 2,
"AdornmentID": 22,
"ApplicabilityID": 222
},{
"LocationID": 3,
"AdornmentID": 33,
"ApplicabilityID": 333
},{
"LocationID": 4,
"AdornmentID": 44,
"ApplicabilityID": 444
}];
var FiterByArray = [{
"filterID": 1,
"ApplicabilityID": 222
},{
"FilterID": 2,
"ApplicabilityID": 444
}];
I need to filter by the applicabilityID and return something similar to what is below...
$scope.filteredList = [{
"LocationID": 1,
"AdornmentID": 11,
"ApplicabilityID": 111
},{
"LocationID": 3,
"AdornmentID": 33,
"ApplicabilityID": 333
}]
If that array was simpler I could do it this way..
var notWhatIWant = [ 222, 444 ];
$scope.FiterByArray = function(e) {
return FiterByArray.indexOf(e.ApplicabilityID) === -1;
}
<div ng-repeat="a in ArrayMain | filter: FiterByArray">
{{ a }}
</div>
This doesn't work with the FiterByArray. I have considered creating a function that loops through the FilterByArray and removed just the ApplicabilityID and creates a new array to filter against, but not sure that is the correct approach for this.
This doesn't work but here is the fiddler I setup to experiment on JSFiddler