当前位置:网站首页>JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
2022-04-23 03:13:00 【S Xiaoxiao s 4D smile】
var json = {
"text" : " Table column name ",
"children" : [{
"text" : " Serial number ",
"children" : [{
"text" : " Serial number one ",
"children" : []
},{
"text" : " No. 2 ",
"children" : []
}]
},{
"text" : " name ",
"children" : []
},{
"text" : " project ",
"children" : [{
"text" : " Item 1 ",
"children" : [{
"text" : " Item 2 ",
"children" : []
}]
}]
}]
};
//colspan Record the number of all leaf nodes of the node
function getLeafCountTree(json) {
if(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;
}
}
getLeafCountTree(json);
版权声明
本文为[S Xiaoxiao s 4D smile]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230310556467.html
边栏推荐
- 2022a special equipment related management (elevator) work license question bank and simulation examination
- Use of slice grammar sugar in C #
- Miniapi of. Net7 (special section): NET7 Preview3
- C WPF UI framework mahapps switching theme
- 交换二叉树中每个结点的左和右
- 类似Jira的十大项目管理软件
- Simple example of using redis in PHP
- Maui initial experience: Cool
- This new feature of C 11, I would like to call it the strongest!
- 2022山东省安全员C证上岗证题库及在线模拟考试
猜你喜欢

2022G2电站锅炉司炉考试题库及在线模拟考试

MySQL port is occupied when building xampp

LoadRunner - performance testing tool

搭建XAMPP时mysql端口被占用

OLED多级菜单记录

一文了解全面静态代码分析
![Eight elder brothers chronicle [4]](/img/87/f695d0275f8a66b9def48a75668d15.png)
Eight elder brothers chronicle [4]

PID debugging of coding motor (speed loop | position loop | follow)
![Use of ADB command [1]](/img/e6/fb8fd6956c226f75b831f8eb46277f.png)
Use of ADB command [1]
![[new version release] componentone added Net 6 and blazor platform control support](/img/08/71e7328f685a5cdd584f1bfdce5f2a.png)
[new version release] componentone added Net 6 and blazor platform control support
随机推荐
可以接收多种数据类型参数——可变参数
ASP. Net 6 middleware series - Custom middleware classes
The most understandable life cycle of dependency injection
全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
2022 P cylinder filling training test questions and simulation test
Fundamentals of software testing and development
Test experience data
使用DFS来解决“字典序排数”问题
This new feature of C 11, I would like to call it the strongest!
. net core current limiting control - aspnetcoreratelimit
LNMP MySQL allows remote access
C syntax pattern matching [switch expression]
Establishing and traversing binary tree
Laravel new route file
研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot
C# 读写二进制文件
2022a special equipment related management (elevator) work license question bank and simulation examination
If the deep replication of objects is realized through C #?
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination