Js multitree traversal problem

has a node of the template
root: [{

]
Name:
children:{
    count:7
    List:{},{},{},{},{},{},{}
}

}]
where every object in List is the same as the root structure.
how to change root into the following template node:
root: [{

]
Name:
children:[{},{},{},{},{},{},{}]

}]

Sep.09,2021

to tell you the truth, I don't understand.

function(root) {
  return [{
    children: root.children.list,
    name: root[0].name
  }]
}

add a judgment, and then the first floor recursion


Recursion:

function traverseTree(list) {
    for (let node of list) {
        if (node.children) {
            if (node.children.List) {
                node.children = node.children.List
            }
            traverseTree(node.children)
        }
    }
}

traverseTree(root)

Recursion, which is generally implemented as above. You'd better understand yourself and write it down, and you'll have no problem next time.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3eb5c-347ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3eb5c-347ff.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?