2

I am having different objects like in the code sample below. I have some checkboxes that filters based on brewer, style, aroma and country. It is filtering only if it has one property in the array.

What is the best solution to make the filter work based on all the elements in the array? I checked some other questions and I couldn't find anything related. It will be great if any of you could help me.

Thanks.

sample of the code here: http://pastie.org/10787362

1 Answer 1

1

You could use filter method of Javascript Array() object.
For example:

$scope.filteredNames = $scope.names.filter(function(element) {
   return
     'brewer1' in element.brewers &&
     'aroma1' in element.aromas
   ;
});

$scope.filteredNames should contain all names with 'brewer1' value in brewers property AND 'aroma1' value in aromas property...

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

3 Comments

You definitely should try to simplify your pastie, keeping only the minimum set of data and code, to help people help you...
Still too much code and data. You can do better... :-)
to be more clear: the problem occurs when the property of the beers objects has multiple values in its array

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.