有一树形结构如下:
const data = [
{
id: "xxxx",
title: "中国xxxx有限公司",
type: "RootCompany",
children: [
{
id: "xxxxx",
title: "本级各部门",
type: "Rootdepartment",
children: [
{
id: "xxxx",
title: "人力资源中心",
children: [
{
id: "xxxxx",
title: "张三",
type: "people",
},
{
id: "xxxx",
title: "李四",
type: "people",
},
],
},
{
id: "xxxx",
title: "战略投资部",
type: "department",
},
],
},
{
id: "xxxx",
title: "中国sxd有限公司",
type: "company",
children: [
{
id: "xxxx",
title: "本级各部门",
type: "department",
children: [
{
id: "xxxx",
title: "企业领导",
type: "department",
children: [
{
id: "xxxxx",
title: "李白",
type: "people",
},
],
},
{
id: "xxxx",
title: "人力资源中心",
type: "department",
},
],
},
],
},
{
id: "xxxx",
title: "中国lsd有限公司",
type: "company",
children: [
{
id: "xxxx",
title: "本级各部门",
type: "Rootdepartment",
children: [
{
id: "xxxx",
title: "公司领导",
type: "department",
},
],
},
{
id: "xxxx",
title: "中国oosd有限公司",
type: "company",
children: [
{
id: "xxxx",
title: "本级各部门",
type: "Rootdepartment",
children: [
{
id: "xxxx",
title: "公司领导",
type: "department",
children: [
{
id: "xxxx",
title: "孙悟空",
type: "people",
},
],
},
],
},
],
},
],
},
],
},
];
像上面这种形式的树形结构,我现在需要在每个type为company或Rootcompany的节点上统计其下子节点type为company或Rootcompany的数量,用childCount属性表示该节点的子节点个数.这个应该怎么弄啊?那位大佬帮帮忙.(就是在进行子节点数量统计时,不要将type为department和Rootdepartment和people的节点计算进去).
只能统计连续父节点的