当前位置:网站首页>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
边栏推荐
- Source generator actual combat
- Passing object type parameters through openfeign
- Blazor University (11) component - replace attributes of subcomponents
- Systemctl start Prometheus + grafana environment
- 使用两种方法来解决“最大回文数乘积”问题
- . net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
- Judge whether there is a leap year in the given year
- [MySQL] left function | right function
- Fight leetcode again (290. Word law)
- C introduction of variable parameter params
猜你喜欢
PID debugging of coding motor (speed loop | position loop | follow)
最通俗易懂的依赖注入与控制反转
Detailed log display of openfeign call
MYSQL03_ SQL overview, rules and specifications, basic select statements, display table structure
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
准备一个月去参加ACM,是一种什么体验?
Blazor University (11) component - replace attributes of subcomponents
Mise en service PID du moteur de codage (anneau de vitesse | anneau de position | suivant)
ASP.NET 6 中间件系列 - 条件中间件
Openfeign timeout setting
随机推荐
【无标题】
Tips in MATLAB
C WPF UI framework mahapps switching theme
Detailed log display of openfeign call
The most easy to understand dependency injection and control inversion
Response processing of openfeign
Xutils3 corrected a bug I reported. Happy
类似Jira的十大项目管理软件
2022A特种设备相关管理(电梯)上岗证题库及模拟考试
Blazor University (12)组件 — 组件生命周期
数据挖掘系列(3)_Excel的数据挖掘插件_估计分析
微软是如何解决 PC 端程序多开问题的
【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
《C语言程序设计》(谭浩强第五版) 第8章 善于利用指针 习题解析与答案
ASP. Net 6 middleware series - execution sequence
Yes Redis using distributed cache in NE6 webapi
一套组合拳,打造一款 IDEA 护眼方案
Vs code setting line feed
Openfeign timeout setting
OLED multi-level menu record