当前位置:网站首页>JS forest leaf node non recursive depth first postorder traversal

JS forest leaf node non recursive depth first postorder traversal

2022-06-25 20:09:00 Fu Zongheng

afterPreview(trees) {
    let nodeList = [].concat(trees);
    while (nodeList.length > 0) {
        let currentNode = nodeList.pop();
        if (currentNode.hasOwnProperty("children")) {
            nodeList = nodeList.concat(currentNode.children);
        }
        else {
            // Here is the leaf node 
            this.dataUpload(currentNode);
        }
    }
    this.showUpdateFlag = true;
    return trees;
}

Please adjust it according to your own data structure .

remarks :

1. In the above methods

trees The structure is : [tree1,tree2,tree3]

tree The structure can be abstracted as :{

    children:[leaf1,leaf2,leaf3]

}

leaf The structure is abstracted as :{

    ......

}

2. If you want a non leaf node , At the first if Handle under

 

 

原网站

版权声明
本文为[Fu Zongheng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190507134669.html