当前位置:网站首页>js递归树结构计算每个节点的叶子节点的数量并且输出
js递归树结构计算每个节点的叶子节点的数量并且输出
2022-04-23 03:11:00 【S筱潇S四维Smile】
var json = {
"text" : "表格列名称",
"children" : [{
"text" : "序号",
"children" : [{
"text" : "序号一",
"children" : []
},{
"text" : "序号二",
"children" : []
}]
},{
"text" : "名称",
"children" : []
},{
"text" : "项目",
"children" : [{
"text" : "项目一",
"children" : [{
"text" : "项目二",
"children" : []
}]
}]
}]
};
//colspan记录节点的所有叶子节点个数
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筱潇S四维Smile]所创,转载请带上原文链接,感谢
https://dongxiao.blog.csdn.net/article/details/124352304
边栏推荐
- [MySQL] left function | right function
- Mysql database
- C introduction of variable parameter params
- ASP.NET 6 中间件系列 - 自定义中间件类
- 2022年度Top9的任务管理系统
- 【无标题】
- How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
- Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
- C#中切片语法糖的使用
- Impact of AOT and single file release on program performance
猜你喜欢

微软是如何解决 PC 端程序多开问题的——内部实现

LoadRunner - performance testing tool

ASP.NET和ASP.NETCore多环境配置对比

. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure

be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?

Detailed log display of openfeign call

Source generator actual combat

全网最全,接口自动化测试怎么做的?精通接口自动化测试详解

Use of slice grammar sugar in C #

荐读 | 分享交易员的书单,向名家请教交易之道,交易精彩无比
随机推荐
TP5 inherits base and uses the variables in base
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
yes. Net future
Xamarin effect Chapter 22 recording effect
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
腾讯视频涨价:一年多赚74亿!关注我领取腾讯VIP会员,周卡低至7元
Miniapi of. Net7 (special section): NET7 Preview3
[untitled]
Yes Redis using distributed cache in NE6 webapi
Use split to solve the "most common words" problem
The most easy to understand dependency injection and control inversion
2022山东省安全员C证上岗证题库及在线模拟考试
Blazor University (11)组件 — 替换子组件的属性
Realize QQ login with PHP
Openfeign timeout setting
[Mysql] LEFT函数 | RIGHT函数
be based on. NETCORE development blog project starblog - (1) why do you need to write your own blog?
Xamarin effect Chapter 21 expandable floating operation button in GIS
C#中元组对象Tuple的使用