I have a tags input box, similar to this except I need to restrict it to allowable combinations.
Here is an example of the possible combinations:
[{
"Combo": [
{
"Id": 1,
"Name": "Tag1"
},
{
"Id": 3,
"Name": "Tag3"
}
]
},
{
"Combo": [
{
"Id": 2,
"Name": "Tag2"
},
{
"Id": 3,
"Name": "Tag3"
},
{
"Id": 4,
"Name": "Tag4"
}
]
}]
I start off by getting a distinct list of Tags and displaying them to the user. As tags are selected, I need to filter the tags by the passed combinations. Therefore, if I select Tag3, I should get the available tags of Tag1, Tag2 & Tag4. I was able to accomplish this by looping through the array of arrays and getting the index of the combos by the array of ids. Like so:
ids.indexOf(combos[a].Combo[c].Id) !== -1
However the issue is when I then add Tag2 to the array of ids, indexOf still includes the first combo because of the Id: 3. What I want is to find the combos that have matching or more Ids.
So when I pass this:
var ids = [3, 2];
I want this combo:
[{
"Combo": [
{
"Id": 2,
"Name": "Tag2"
},
{
"Id": 3,
"Name": "Tag3"
},
{
"Id": 4,
"Name": "Tag4"
}
]
}]
It is a bit messy, but here is the jsfiddle example I have been working on. http://jsfiddle.net/4L3kr052/