I have a bunch of tasks and I need to find all children based on the task I click. I would like an array of position [ 1,2, 3] to come back so I can work with those rows.
Here is an example.
var taskAR = [
{
"isParent": true,
"parentID": null,
"level": 0
},
{
"isParent": true,
"parentID": 0,
"level": 1
},
{
"isParent": true,
"parentID": 1,
"level": 2
},
{
"isParent": false,
"parentID": 2,
"level": 3
},
{
"isParent": false,
"parentID": 2,
"level": 3
},
{
"isParent": false,
"parentID": null,
"level": 0
},
{
"isParent": true,
"parentID": null,
"level": 0
},
{
"isParent": false,
"parentID": 7,
"level": 1
}
];
function getNestedChildren(arr, parentID) {
var out = []
for (var x = 0, len = arr.length; x < len ; x++) {
var d = arr[x];
if (d.parentID == parentID) {
var children = getNestedChildren(arr, x);
if (children.length) {
d.parentID = x;
}
out.push(x)
}
}
return out
}
getNestedChildren(this.master.tasks, parentID)
thanks for the help