Question

I have a JSON File with Tasks. They are structured as follows:

[
{
    "id":"1",
    "name":"task1",
    "tags":["tag1","tag2","tag3"]
},
{
    "id":"2",
    "name":"task2",
    "tags":["tag4","tag2","tag5"]
},
{
    "id":"3",
    "name":"task3",
    "tags":["tag3"]
}
]

Here's a Plunkr for what I want http://plnkr.co/edit/kMhiHDyybHYxGfV7W39z?p=preview

Basically, this is what I want : http://jsfiddle.net/TahmidTanzim/N9Vqk/

I've looked through various SO questions and they all suggest I am doing it right. However I don't understand where I am going wrong. I want only those tasks that contain the selectedTag to be displayed in the red list.

Thanks!

Was it helpful?

Solution

Just change filters to compare inner tags using arrays.

myapp.filter('tagFilter',function()
{
    return function(Data,selectedTags)
    {
        if(selectedTags.length===0) return Data;
        var tempData=[];
        for(var i  in Data) {
            for(var z in Data[i].tags) {
                for(var k in selectedTags) {
                    var value = selectedTags[k];
                    if(value == Data[i].tags[z]) {
                        tempData.push(Data[i]);
                        break;             
                    }
                }
            }
        }
        return tempData;
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top