当前位置:网站首页>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
边栏推荐
- [authentication / authorization] customize an authentication handler
- Load view Caton
- Use of slice grammar sugar in C #
- 手机连接电脑后,QT的QDIR怎么读取手机文件路径
- Laravel's own paging query
- AOT和单文件发布对程序性能的影响
- Source Generator实战
- Tencent video VIP member, weekly card special price of 9 yuan! Tencent official direct charging, members take effect immediately!
- Source generator actual combat
- Mysql database design specification
猜你喜欢

搭建XAMPP时mysql端口被占用

Use of slice grammar sugar in C #

数据挖掘系列(3)_Excel的数据挖掘插件_估计分析

由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。

Yes Redis using distributed cache in NE6 webapi

TP5 customization in extend directory succeeded and failed. Return information

全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆

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

一套组合拳,打造一款 IDEA 护眼方案

全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
随机推荐
C#中元组对象Tuple的使用
ASP.NET 6 中间件系列 - 自定义中间件类
Fight leetcode again (290. Word law)
2022山东省安全员C证上岗证题库及在线模拟考试
Queue storage and circular queue
MYSQL04_ Exercises corresponding to arithmetic, logic, bit, operator and operator
Recursion - outputs continuously increasing numbers
[MySQL] left function | right function
Laravel new route file
Detailed log display of openfeign call
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
Passing object type parameters through openfeign
2022G2电站锅炉司炉考试题库及在线模拟考试
由于3²+4²=5²,所以称‘3,4,5‘为勾股数,求n(包括n)以内所有勾股数数组。
最通俗易懂的依赖注入与控制反转
C language to achieve address book - (static version)
交换二叉树中每个结点的左和右
After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
搭建XAMPP时mysql端口被占用
Use split to solve the "most common words" problem