I have three categories of controls, each with several options:
<ul class="series-selector-items">
<li id="filter-type-A">A</li>
<li id="filter-type-B">B</li>
<li id="filter-type-C">C</li>
</ul>
<ul class="series-selector-items">
<li id="filter-type-E">E</li>
<li id="filter-type-F">F</li>
<li id="filter-type-G">G</li>
</ul>
<ul class="series-selector-items">
<li id="filter-type-H">H</li>
<li id="filter-type-I">I</li>
<li id="filter-type-J">J</li>
<li id="filter-type-K">K</li>
</ul>
Then I have a list with items that have combinations of attributes from the above controls:
<ul>
<li class="A E H">Item AEH</li>
<li class="A F I">Item AFI</li>
<li class="A G J">Item AGJ</li>
<li class="A G H">Item AGH</li>
<li class="B E H">Item BEH</li>
<li class="B F H">Item BFH</li>
<li class="B F H">Item BFH</li>
<li class="C E I">Item CEI</li>
<li class="C G K">Item CEI</li>
etc etc...
</ul>
I am trying to find a way to filter results based on combinations of selected control options. I need to be able to select any combination of control options, (ex. A E H) and show all the items that have the correct attributes (item AEH).
Multiple options should be selectable in each category (A B E K), and the categories should work together to show options that have the correct combination of elements. If multiple options are selected from the same category, their results should still show up. I have made the control list as li's but they could also be checkboxes.
What's the best way to do this with jQuery?
EDIT: Here is one approach I tried so far, adding selected options to an array:
var seriesSelected = [];
$('ul.series-selector-items').click(function(){
//Select the series clicked and give it the "selected" class
$(this).toggleClass("selected");
//Once selected, add the series to the seriesSelected array
if ($(this).hasClass('selected')) {
seriesSelected.push($(this).attr('id'));
}
//If de-selecting (by toggling off the "selected class"), then remove from the seriesSelected array
else {
seriesToRemove = $(this).attr('id');
seriesSelected = $.grep(seriesSelected, function(value) {
return seriesToRemove != value;
});
}
});
Not sure where to go from there...