本次的工作主要是计算节点橙色部分标记的子节点数量,没有橙色部分的节点,只是隐藏了橙色部分
json数据格式类似这种:
{
"name": "aaa",
"Children": [
{
"name": "aaa",
"Children": [
{
"name": "ccc",
"Children": [
{
"name": "ccc",
"Children": []
}
]
},
{
"name": "eee",
"Children": []
}
]
}
]
}
实现代码:
计算节点数:
function getLeafCountTree(data, level