0

I have a JSON object as follows:

{"email":null,"fullList":true,"listOfSomething":[
{
"contactEmailAddress": "[email protected]",
"somethingId": 11060767,
"other": "whatever"
},
{
"contactEmailAddress": "[email protected]",
"somethingId": 8499447,
"other": "whatever"
}, {
"contactEmailAddress": "[email protected]",
"somethingId": 3234664,
"other": "whatever"
},  {
"contactEmailAddress": "[email protected]",
"somethingId": 3233245,
"other": "whatever"
}
]
,"numOfResults":22}

In angular, I want to filter this list by an array of selected ID's, to match the key "SomethingID", within the key "listOfSomething"

My array of ID's to match against is formatted as:

[16199615,16199619]

My current filter just returns the entire list, unfiltered:

.filter('somethingFilter', ['somethingListService', function(somethingListService) {
domainsSelected = somethingListService.getSomethingSelected();
return function(array) {
    return array.filter(function(item) {
       return somethingSelected.indexOf(item.somethingId) === -1;
    });
};
}]);

I've tried so many different methods, but can find no examples where an array of numbers is matched against a nested JSON object, that has no numeric indexing.

1
  • Davin - my mistake, was trying to obfuscate company sensitive code before posting question and forgot to change a variable name. Commented Dec 17, 2014 at 14:49

1 Answer 1

2

Here is a working example, of what I think you want to achieve: http://jsfiddle.net/martinczerwi/kdmqvw19/3/

I've noticed, your filter returns true if the ID is not found, that's why the whole array is dumped. Also the ID array's name was wrong. Should probably be:

return domainsSelected.indexOf(item.somethingId) !== -1;

In my example I've added an ID from the data to the filter IDs.

Sign up to request clarification or add additional context in comments.

1 Comment

That's perfect - can't believe I didn't spot that obvious mistake, been working on the code for too long! - Thanks martinczerwi !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.