Im little bit stuck on mapping an object recursively, this is the source object :
source data :
{
"id": "41055788",
"parent_id": "00000000",
"organization": "Consejo Directivo",
"level": 1,
"children": [
{
"id": "51cd732c",
"parent_id": "41055788",
"organization": "Dirección General",
"children": [
{
"id": "28cd78ff",
"parent_id": "51cd732c",
"organization": "Direcciones Regionales",
"children": []
....
** I've been trying to figure out how to iterate through the tree and result expected:**
{
"data":{
"id": "41055788",
"parent_id": "00000000",
"organization": "Consejo Directivo",
"level": 1
},
"children": [
{
"data": {
"id": "51cd732c",
"parent_id": "41055788",
"organization": "Dirección General"
},
"children": [ ] ...
this is what im on till now without success:
**function tranformTransverse(root, tree) {
let rmChd = Object.assign({}, root);
delete rmChd['children'];
this.dataTree.push({
data : rmChd,
children : (!!root && root.hasOwnProperty("children")) && root['children']
});
if ((!!root && root.hasOwnProperty("children")) && root['children'] instanceof Array)
root['children'].forEach(child => {
this.tranformTransverse(child, tree);
});
}**
Any Idea how to achieve this result?