I'm trying to make a recursive method that when you click on a hierarchy all parents will be enabled.
I know how to make recursive methods top to down, for example, find id one of children but I dont know how to make a recursive method down to top.
For example:
const data = [{
"id": 1,
"parentId": null,
"selected": false,
"children": [{
"id": 2,
"parentId": 1,
"selected": false,
"children": [{
"id": 3,
"parentId": 2,
"selected": false,
"children": [{
"id": 4,
"parentId": 3,
"selected": false,
"children": []
}]
}]
}]
}, {
"id": 1,
"parentId": null,
"selected": true,
"children": []
}, {
"id": 1,
"parentId": null,
"selected": true,
"children": []
}]
When the item with id 4 is selected, the selected property of all its ancestors should be set to true.