On the Recursive problem of Tree structure

the following is the interface simulation data. I need to perform different logic when the user clicks according to different parent nodes, that is, through recursion, the user clicks on any tree node, how to know the current layer node

for example, if the user clicks on the module node, it grays out the page button and forbids the user from clicking. If the click performance, let the button be restored and highlighted to allow the user to click, that is, how do I know which node the user clicked on? it is impossible to judge by the name of the node. How many layers of the node are unknown

?
let arr = [{
        "id": 90,
        "name": "MS",
        "pareid": 0,
        "children": [{
            "id": 736,
            "name": "",
            "pareid": 90,
            "children": [{
                "id": 739,
                "name": "",
                "pareid": 736,
                "children": [{
                    "id": 971,
                    "name": "",
                    "pareid": 739,
                }]
            }, {
                "id": 741,
                "name": "_a",
                "pareid": 736,
                "children": [{
                    "id": 742,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 743,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 744,
                    "name": "_a",
                    "pareid": 741,
                }, {
                    "id": 969,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 972,
                    "name": "_s",
                    "pareid": 741,
                }, {
                    "id": 985,
                    "name": "_a",
                    "pareid": 741,
                }, {
                    "id": 995,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 1008,
                    "name": "_",
                    "pareid": 741,
                }, {
                    "id": 1009,
                    "name": "_",
                    "pareid": 741,
                }, {
                    "id": 1010,
                    "name": "_",
                    "pareid": 741,
                }, {
                    "id": 1019,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 1032,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 1033,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 1034,
                    "name": "",
                    "pareid": 741,
                }, {
                    "id": 1035,
                    "name": "_2",
                    "pareid": 741,
                }, {
                    "id": 1036,
                    "name": "_w",
                    "pareid": 741,
                }, {
                    "id": 1037,
                    "name": "a",
                    "pareid": 741,
                }]
            }]
        }, {
            "id": 997,
            "name": "",
            "pareid": 90,
            "children": [{
                "id": 996,
                "name": "",
                "pareid": 997,
            }, {
                "id": 1024,
                "name": "hg",
                "pareid": 997,
            }, {
                "id": 1025,
                "name": "",
                "pareid": 997,
            }, {
                "id": 1026,
                "name": "",
                "pareid": 997,
            }, {
                "id": 1028,
                "name": "_kl",
                "pareid": 997,
            }, {
                "id": 1029,
                "name": "h",
                "pareid": 997,
            }, {
                "id": 1040,
                "name": "_e",
                "pareid": 997,
            }, {
                "id": 1041,
                "name": "_df",
                "pareid": 997,
            }, {
                "id": 1340,
                "name": "_",
                "pareid": 997,
            }, {
                "id": 1350,
                "name": "r_",
                "pareid": 997,
            }, {
                "id": 1351,
                "name": "_n",
                "pareid": 997,
            }, {
                "id": 1352,
                "name": "v_",
                "pareid": 997,
            }, {
                "id": 1353,
                "name": "_g",
                "pareid": 997,
            }, {
                "id": 1354,
                "name": "_1v1",
                "pareid": 997,
            }, {
                "id": 1355,
                "name": "_1vn",
                "pareid": 997,
            }]
        }]
    }];
    
    recursion = (cityData) => {
        for (let i = 0; i < cityData.length; iPP) {
            const childs = cityData[i].children;
            if(childs && childs.length > 0) {// 
                recursion(childs);
            }
        }
    }
    recursion(arr);

recursion = (cityData, time = 0) => {
        //  time 
        for (let i = 0; i < cityData.length; iPP) {
            const childs = cityData[i].children;
            if(childs && childs.length > 0) {// 
                recursion(childs, time + 1);
            }
        }
    }
    recursion(arr);

can


put a reference to the parent node in each child node. The parent of the root node is null, and then execute on the current node:
var cnt = 0;
for (var n = currentNode; n.parent! = null; n = n.parent) cntPP;

so that at the end of the loop, cnt is the number of layers of the current node

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-1b228d9-2ada4.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-1b228d9-2ada4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?