当前位置:网站首页>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
边栏推荐
- 中后二叉建树
- 【无标题】
- “如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
- Xamarin effect Chapter 21 expandable floating operation button in GIS
- Use of metagroup object tuple in C
- The most understandable life cycle of dependency injection
- Eight elder brothers chronicle [4]
- 2022年做跨境电商五大技巧小分享
- The most easy to understand dependency injection and control inversion
- TP5 where query one field is not equal to multiple values
猜你喜欢
The most easy to understand service container and scope of dependency injection
2022a special equipment related management (elevator) work license question bank and simulation examination
C# 读写二进制文件
A set of combination boxing to create an idea eye protection scheme
Data mining series (3)_ Data mining plug-in for Excel_ Estimation analysis
OLED multi-level menu record
Impact of AOT and single file release on program performance
General testing technology [1] classification of testing
Laravel's own paging query
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
随机推荐
Simple example of using redis in PHP
What kind of experience is it to prepare for a month to participate in ACM?
Course design of Database Principle -- material distribution management system
建立与遍历二叉树
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
如果通过 C# 实现对象的深复制 ?
General testing technology [1] classification of testing
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
Recursion - outputs continuously increasing numbers
交换二叉树中每个结点的左和右
Laravel's own paging query
使用split来解决“最常见的单词”问题
2022T电梯修理考试模拟100题及在线模拟考试
Preview of converting doc and PDF to SWF file
LNMP MySQL allows remote access
编码电机PID调试(速度环|位置环|跟随)
C WPF UI framework mahapps switching theme
C language to achieve address book - (static version)
This new feature of C 11, I would like to call it the strongest!
7-11 rearrange the linked list (25 points)