I am trying to find an Object by ID and remove it. (Of course if this object has subTasks all Objects hanging on this tree are removed too). I have a structure like this (For example), which can grow very big and deep:
[ { "id": 0, "lane": 0, "name": "Task A", "start": 0, "end": 10000, "subTasks": [ { "id": "0.1", "lane": 0, "name": "Subtask", "start": 0, "end": 10000, "class": "danger", "sublane": 0, "subTasks": [ { "id": "0.1.1", "name": "Subtask", "start": 0, "end": 10000, "subTasks": [ { "id": "0.1.1.1", "name": "Subtask", "start": 0, "end": 10000, "subTasks": [ { "id": "0.1.1.1.1", "name": "Subtask", "start": 0, "end": 10000 }, { "id": "0.1.1.1.2", "name": "Subtask", "start": 0, "end": 10000 } ] }, { "id": "0.1.1.2", "name": "Subtask", "start": 0, "end": 10000 } ] }, { "id": "0.1.2", "name": "Subtask", "start": 0, "end": 10000 }, { "id": "0.1.3", "name": "Subtask", "start": 0, "end": 10000 } ] }, { "id": "0.2", "name": "Subtask", "start": 0, "end": 10000 } ], "class": "danger", "sublane": 0 }, { "id": 1, "lane": 2, "name": "Task B", "start": 15000, "end": 25000, ], "class": "success", "sublane": 0 } ] Now I want to remove the ID = 0.1.1.1.1 for example, but it should work with every other Object the same way, no matter how deep it is nested.
For finding and editing Im using this dfs algorithm:
edit: function (name, start, end) { for (let obj of gantt.items()) { result = dfs(obj, id); if (result) { result.name = name; result.start = start; result.end = end; } } dfs: function (obj, targetId) { if (obj.id === targetId) { return obj; } if (obj.subTasks) { for (let item of obj.subTasks) { let check = dfs(item, targetId); if (check) { return check; } } } return null; }, But how can I remove/delete the specific Object?
Array.filter(...)method.