当前位置:网站首页>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
边栏推荐
- Eight elder brothers chronicle [4]
- Queue storage and circular queue
- Data mining series (3)_ Data mining plug-in for Excel_ Estimation analysis
- TP5 customization in extend directory succeeded and failed. Return information
- 利用栈的回溯来解决“文件的最长绝对路径”问题
- C syntax pattern matching [switch expression]
- C WPF UI framework mahapps switching theme
- LNMP MySQL allows remote access
- 在.NE6 WebApi中使用分布式缓存Redis
- 編碼電機PID調試(速度環|比特置環|跟隨)
猜你喜欢
![[untitled]](/img/b5/6ce72422bbf330610c747ceb482944.jpg)
[untitled]

《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案

腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!

C WPF UI framework mahapps switching theme

Realize QQ login with PHP

Course design of Database Principle -- material distribution management system

C language to achieve address book - (static version)

搭建XAMPP时mysql端口被占用

Aspnetcore configuration multi environment log4net configuration file

准备一个月去参加ACM,是一种什么体验?
随机推荐
2022 P cylinder filling training test questions and simulation test
. net core current limiting control - aspnetcoreratelimit
Use of metagroup object tuple in C
2022G2电站锅炉司炉考试题库及在线模拟考试
Configuration table and page information automatically generate curd operation page
中后二叉建树
Tencent video price rise: earn more than 7.4 billion a year! Pay attention to me to receive Tencent VIP members, and the weekly card is as low as 7 yuan
利用正反遍历来解决“字符的最短距离”问题
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
Student achievement management
Fight leetcode again (290. Word law)
Charles uses three ways to modify requests and responses
OLED multi-level menu record
搭建XAMPP时mysql端口被占用
7-11 重排链表 (25 分)
LNMP MySQL allows remote access
队列的存储和循环队列
Maui initial experience: Cool
一套关于 内存对齐 的C#面试题,做错的人很多!
使用DFS来解决“字典序排数”问题