SOURCE

 const json = [
    {
        "id": "9a6426bea6f54f10a00e3e5a18e89308",
        "finalChildCount": 0,
        "name": "上级满意度",       
        "children": [
            {
                "id": "d39229b3c0834d8c9ba8559c34aea86f",
                "finalChildCount": 0,
                "name": "多",
                "children": [  {
                "id": "6b9bdc3fd8bc4fe18d61e6fc86764f4a",
                "finalChildCount": 0,
                "name": "按照上级要求及时上报各类安全工作计划、总结等安全文件",            
                "children": null
            },
            {
                "id": "27767320d7574f579b3b0ac66062e81b",
                 "finalChildCount": 0,
                "name": "积极配合上级主管部门开展各类安全检查,并时完成隐患整改",            
                "children": [ {
                "id": "f2a175da919740adb229167395984844",
                "finalChildCount": 0,
                "name": "积极配合上级部门开展各类安全活动",
                "children": null
            }]
            },
            {
                "id": "f2a175da919740adb229167395984844",
                "finalChildCount": 0,
                "name": "积极配合上级部门开展各类安全活动",
                "children": null
            }]
            },
            {
                "id": "6b9bdc3fd8bc4fe18d61e6fc86764f4a",
                "finalChildCount": 0,
                "name": "按照上级要求及时上报各类安全工作计划、总结等安全文件",            
                "children": null
            },
            {
                "id": "27767320d7574f579b3b0ac66062e81b",
                 "finalChildCount": 0,
                "name": "积极配合上级主管部门开展各类安全检查,并时完成隐患整改",            
                "children": null
            },
            {
                "id": "f2a175da919740adb229167395984844",
                "finalChildCount": 0,
                "name": "积极配合上级部门开展各类安全活动",
                "children": null
            }
        ]
    },
    {
        "id": "875f5da79bdb462d88a459d387154bd7",
        "finalChildCount": 0,
        "name": "法定履职情况",       
        "children": [
            {
                "id": "f9a5ec8328364b3c8f21b07ec5d2e254",
                "finalChildCount": 0,
                "name": "认真贯彻法律法规,按照法律法规要求,认真开展各项工作;\n日常安全管理工作符合法律法规要求",
                "children": null
            }
        ]
    }
]
 ;
                //colspan记录节点的所有叶子节点个数
        function getLeafCountTree(json) {
            if(json.children == null || json.children.length == 0){
                json.colspan = 1;
                return 1;
            }else{
                var leafCount = 0;
                for(var i = 0 ; i < json.children.length ; i++){
                    leafCount = leafCount + getLeafCountTree(json.children[i]);
                }
                json.colspan = leafCount;
                return leafCount;
            }
        }

        var x = getLeafCountTree(json);
        console.log(x);
console 命令行工具 X clear

                    
>
console