I am currently working with treeview data that looks like this:
[
{
"id":132,
"parent_id":0,
"title":"Item 1",
"description":"",
"nodes":[
{
"id":133,
"parent_id":132,
"title":"Item 1.1",
"description":"",
"nodes":[
{
"id":134,
"parent_id":133,
"title":"Item 1.1.1",
"description":"",
"nodes":[],
}
]
}
]
},
{
"id":135,
"parent_id":0,
"title":"Item 2",
"description":"",
"nodes":[ ]
},
{
"id":136,
"parent_id":0,
"title":"Item 3",
"description":"",
"nodes":[
{
"id":137,
"parent_id":136,
"title":"Item 3.1",
"description":"",
"nodes":[ ]
}
]
}
]
My goal is to filter the data based on both Title and Description in all children values, and if a matching child value is found, display all its parent items according to the hierarchy.
I have attempted to achieve this using the following code snippet, but it only filters by the title of the first parent item:
this.visible = function (item) {
return !(this.query && this.query.length > 0 &&
item.title.indexOf(this.query) == -1);
};