我正在尝试从经理下面获取员工总数,并尝试从下面的嵌套JSON中添加IsManager = True来添加员工总数
[{
"name": "Wendeline",
"IsManager": "TRUE",
"children": [{
"name": "Goraud",
"IsManager": "TRUE",
"EmployeeNumber": 706997,
"children": [{
"name": "Mersey",
"IsManager": "FALSE",
"EmployeeNumber": 102752,
"children": []
}, {
"name": "Elli",
"IsManager": "FALSE",
"EmployeeNumber": 742047,
"children": [{
"name": "Hans",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Bald",
"IsManager": "FALSE",
"EmployeeNumber": 741064,
"children": []
}, {
"name": "Truda",
"IsManager": "FALSE",
"EmployeeNumber": 739162,
"children": []
}, {
"name": "Matty",
"IsManager": "FALSE",
"EmployeeNumber": 717067,
"children": []
}, {
"name": "Ola",
"IsManager": "TRUE",
"EmployeeNumber": 713122,
"children": [{
"name": "Frankie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Quint",
"IsManager": "FALSE",
"EmployeeNumber": 705616,
"children": []
}, {
"name": "Georgi",
"IsManager": "FALSE",
"EmployeeNumber": 733001,
"children": []
}, {
"name": "Danie",
"IsManager": "FALSE",
"EmployeeNumber": 742962,
"children": []
}, {
"name": "Judon",
"IsManager": "FALSE",
"EmployeeNumber": 750620,
"children": []
}, {
"name": "Nellie",
"IsManager": "FALSE",
"EmployeeNumber": 101490,
"children": []
}, {
"name": "Marji",
"IsManager": "FALSE",
"EmployeeNumber": 705660,
"children": []
}, {
"name": "Adelaida",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Bing",
"IsManager": "FALSE",
"EmployeeNumber": 745205,
"children": []
}, {
"name": "Odilia",
"IsManager": "FALSE",
"EmployeeNumber": 718622,
"children": []
}]
}, {
"name": "Bernardina",
"IsManager": "FALSE",
"EmployeeNumber": 726710,
"children": []
}, {
"name": "Myca",
"IsManager": "FALSE",
"EmployeeNumber": 726163,
"children": []
}, {
"name": "Husain",
"IsManager": "FALSE",
"EmployeeNumber": 728267,
"children": []
}, {
"name": "Cristie",
"IsManager": "FALSE",
"EmployeeNumber": 750267,
"children": []
}, {
"name": "Nikolai",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "James",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Ashbey",
"IsManager": "FALSE",
"EmployeeNumber": 744719,
"children": []
}, {
"name": "Flss",
"IsManager": "FALSE",
"EmployeeNumber": 746709,
"children": []
}, {
"name": "Felisha",
"IsManager": "FALSE",
"EmployeeNumber": 739945,
"children": [{
"name": "Zelig",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Jakob",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}]
}, {
"name": "Cointon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Jo",
"IsManager": "TRUE",
"EmployeeNumber": 716884,
"children": [{
"name": "Sylvia",
"IsManager": "FALSE",
"EmployeeNumber": 744160,
"children": []
}, {
"name": "Vicki",
"IsManager": "FALSE",
"EmployeeNumber": 735637,
"children": []
}, {
"name": "Blanche",
"IsManager": "FALSE",
"EmployeeNumber": 729407,
"children": []
}, {
"name": "Mirabelle",
"IsManager": "FALSE",
"EmployeeNumber": 731551,
"children": []
}, {
"name": "Floria",
"IsManager": "FALSE",
"EmployeeNumber": 727255,
"children": []
}, {
"name": "Flossie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Anny",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hyatt",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Juli",
"IsManager": "FALSE",
"EmployeeNumber": 740132,
"children": []
}, {
"name": "Isacco",
"IsManager": "FALSE",
"EmployeeNumber": 742246,
"children": []
}, {
"name": "Fleurette",
"IsManager": "FALSE",
"EmployeeNumber": 742205,
"children": []
}, {
"name": "Dicky",
"IsManager": "FALSE",
"EmployeeNumber": 742736,
"children": []
}, {
"name": "Wini",
"IsManager": "FALSE",
"EmployeeNumber": 741836,
"children": []
}, {
"name": "Elden",
"IsManager": "FALSE",
"EmployeeNumber": 743234,
"children": []
}, {
"name": "Marjie",
"IsManager": "FALSE",
"EmployeeNumber": 740196,
"children": []
}, {
"name": "Vanna",
"IsManager": "FALSE",
"EmployeeNumber": 738053,
"children": []
}, {
"name": "Emilio",
"IsManager": "FALSE",
"EmployeeNumber": 751901,
"children": []
}, {
"name": "Enrique",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Lilas",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Elita",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hyacintha",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Markus",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Calhoun",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Melisande",
"IsManager": "FALSE",
"EmployeeNumber": 748847,
"children": []
}, {
"name": "Haroun",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Niles",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Adorne",
"IsManager": "FALSE",
"EmployeeNumber": 724804,
"children": []
}, {
"name": "Dianne",
"IsManager": "FALSE",
"EmployeeNumber": 724863,
"children": []
}, {
"name": "Faye",
"IsManager": "FALSE",
"EmployeeNumber": 732329,
"children": []
}, {
"name": "Tabina",
"IsManager": "FALSE",
"EmployeeNumber": 724910,
"children": []
}]
}, {
"name": "Spike",
"IsManager": "FALSE",
"EmployeeNumber": 732941,
"children": [{
"name": "Reta",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Cirillo",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Berty",
"IsManager": "TRUE",
"EmployeeNumber": 726527,
"children": [{
"name": "Gerrie",
"IsManager": "TRUE",
"EmployeeNumber": 727939,
"children": [{
"name": "Kelci",
"IsManager": "FALSE",
"EmployeeNumber": 739483,
"children": []
}, {
"name": "Alexandros",
"IsManager": "FALSE",
"EmployeeNumber": 723369,
"children": []
}, {
"name": "Loreen",
"IsManager": "FALSE",
"EmployeeNumber": 746432,
"children": []
}, {
"name": "Cortie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Keven",
"IsManager": "FALSE",
"EmployeeNumber": 723060,
"children": []
}, {
"name": "Shanie",
"IsManager": "FALSE",
"EmployeeNumber": 707562,
"children": []
}, {
"name": "Hatti",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Tammi",
"IsManager": "FALSE",
"EmployeeNumber": 717763,
"children": []
}, {
"name": "Blondell",
"IsManager": "FALSE",
"EmployeeNumber": 731167,
"children": []
}]
}, {
"name": "Bellina",
"IsManager": "FALSE",
"EmployeeNumber": 731162,
"children": []
}, {
"name": "Constancia",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Dieter",
"IsManager": "FALSE",
"EmployeeNumber": 725942,
"children": []
}, {
"name": "Illa",
"IsManager": "FALSE",
"EmployeeNumber": 733953,
"children": [{
"name": "Roley",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Talbot",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Theodora",
"IsManager": "TRUE",
"EmployeeNumber": 721734,
"children": [{
"name": "Ebeneser",
"IsManager": "FALSE",
"EmployeeNumber": 741729,
"children": []
}, {
"name": "Allie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Benita",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Elmira",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Dene",
"IsManager": "FALSE",
"EmployeeNumber": 739572,
"children": []
}, {
"name": "Hamil",
"IsManager": "FALSE",
"EmployeeNumber": 731393,
"children": []
}, {
"name": "Fitzgerald",
"IsManager": "FALSE",
"EmployeeNumber": 710334,
"children": [{
"name": "Leon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Mignon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Constantina",
"IsManager": "FALSE",
"EmployeeNumber": 744831,
"children": []
}, {
"name": "Alysa",
"IsManager": "FALSE",
"EmployeeNumber": 736292,
"children": []
}]
}]
}, {
"name": "Garrik",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Onofredo",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Josefa",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Nan",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Birgit",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Ashlan",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Rod",
"IsManager": "TRUE",
"EmployeeNumber": 726043,
"children": [{
"name": "Lorie",
"IsManager": "TRUE",
"EmployeeNumber": 711520,
"children": [{
"name": "Norris",
"IsManager": "FALSE",
"EmployeeNumber": 736426,
"children": []
}, {
"name": "Josefa",
"IsManager": "FALSE",
"EmployeeNumber": 728365,
"children": []
}, {
"name": "Carma",
"IsManager": "FALSE",
"EmployeeNumber": 751153,
"children": []
}, {
"name": "Rozelle",
"IsManager": "FALSE",
"EmployeeNumber": 738418,
"children": []
}, {
"name": "Tine",
"IsManager": "FALSE",
"EmployeeNumber": 721367,
"children": []
}, {
"name": "Ransom",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hildagarde",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Grant",
"IsManager": "FALSE",
"EmployeeNumber": 712948,
"children": []
}]
}, {
"name": "Karilynn",
"IsManager": "FALSE",
"EmployeeNumber": 102152,
"children": []
}, {
"name": "Tine",
"IsManager": "FALSE",
"EmployeeNumber": 717285,
"children": []
}, {
"name": "Lenna",
"IsManager": "FALSE",
"EmployeeNumber": 707659,
"children": []
}, {
"name": "Fanni",
"IsManager": "TRUE",
"EmployeeNumber": 102936,
"children": [{
"name": "Nani",
"IsManager": "FALSE",
"EmployeeNumber": 726746,
"children": []
}, {
"name": "Jethro",
"IsManager": "FALSE",
"EmployeeNumber": 744442,
"children": []
}, {
"name": "Olenka",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Morena",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Susana",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hammad",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Erwin",
"IsManager": "FALSE",
"EmployeeNumber": 711550,
"children": []
}]
}, {
"name": "Petr",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}]
}]
我尝试了以下链接:Headcount under nested JSON
但这是直接数。我需要全部孩子数。 我正在寻找以下输出
如果IsManager = True,则将此TotalCount作为键值添加到父级
“ Key(TotalCount)”:“ TotalChildrencount / TotalTBDCount / TotalEmployeeCount(只有拥有员工编号的人)”
示例:
{ “ name”:“ Wendeline”, “ IsManager”:“ TRUE”, “ count”:“ 131 / 44TBD / 87FTE” }
像Wendeline一样,所有拥有“ IsManager:True”的人都应该显示孩子总数Count / Total TBD / Total FTE
任何帮助将不胜感激。
答案 0 :(得分:0)
编辑:不确定我第一次回答时是否理解您的问题。下面是更新的答案。
不确定构造数据的方式是否正确。但是,这是我构建的一个递归函数,可以完成您尝试做的事情。
let data = [
{
"name": "Wendeline",
"IsManager": "TRUE",
"children": [
{
"name": "Goraud",
"IsManager": "TRUE",
"EmployeeNumber": 706997,
"children": [
{
"name": "Mersey",
"IsManager": "FALSE",
"EmployeeNumber": 102752,
"children": []
},
{
"name": "Elli",
"IsManager": "FALSE",
"EmployeeNumber": 742047,
"children": [
{
"name": "Hans",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}
]
},
{
"name": "Bald",
"IsManager": "FALSE",
"EmployeeNumber": 741064,
"children": []
},
{
"name": "Truda",
"IsManager": "FALSE",
"EmployeeNumber": 739162,
"children": []
},
{
"name": "Matty",
"IsManager": "FALSE",
"EmployeeNumber": 717067,
"children": []
},
{
"name": "Ola",
"IsManager": "TRUE",
"EmployeeNumber": 713122,
"children": [
{
"name": "Frankie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Quint",
"IsManager": "FALSE",
"EmployeeNumber": 705616,
"children": []
},
{
"name": "Georgi",
"IsManager": "FALSE",
"EmployeeNumber": 733001,
"children": []
},
{
"name": "Danie",
"IsManager": "FALSE",
"EmployeeNumber": 742962,
"children": []
},
{
"name": "Judon",
"IsManager": "FALSE",
"EmployeeNumber": 750620,
"children": []
},
{
"name": "Nellie",
"IsManager": "FALSE",
"EmployeeNumber": 101490,
"children": []
},
{
"name": "Marji",
"IsManager": "FALSE",
"EmployeeNumber": 705660,
"children": []
},
{
"name": "Adelaida",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Bing",
"IsManager": "FALSE",
"EmployeeNumber": 745205,
"children": []
},
{
"name": "Odilia",
"IsManager": "FALSE",
"EmployeeNumber": 718622,
"children": []
}
]
},
{
"name": "Bernardina",
"IsManager": "FALSE",
"EmployeeNumber": 726710,
"children": []
},
{
"name": "Myca",
"IsManager": "FALSE",
"EmployeeNumber": 726163,
"children": []
},
{
"name": "Husain",
"IsManager": "FALSE",
"EmployeeNumber": 728267,
"children": []
},
{
"name": "Cristie",
"IsManager": "FALSE",
"EmployeeNumber": 750267,
"children": []
},
{
"name": "Nikolai",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "James",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Ashbey",
"IsManager": "FALSE",
"EmployeeNumber": 744719,
"children": []
},
{
"name": "Flss",
"IsManager": "FALSE",
"EmployeeNumber": 746709,
"children": []
},
{
"name": "Felisha",
"IsManager": "FALSE",
"EmployeeNumber": 739945,
"children": [
{
"name": "Zelig",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Jakob",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}
]
}
]
},
{
"name": "Cointon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Jo",
"IsManager": "TRUE",
"EmployeeNumber": 716884,
"children": [
{
"name": "Sylvia",
"IsManager": "FALSE",
"EmployeeNumber": 744160,
"children": []
},
{
"name": "Vicki",
"IsManager": "FALSE",
"EmployeeNumber": 735637,
"children": []
},
{
"name": "Blanche",
"IsManager": "FALSE",
"EmployeeNumber": 729407,
"children": []
},
{
"name": "Mirabelle",
"IsManager": "FALSE",
"EmployeeNumber": 731551,
"children": []
},
{
"name": "Floria",
"IsManager": "FALSE",
"EmployeeNumber": 727255,
"children": []
},
{
"name": "Flossie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Anny",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Hyatt",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Juli",
"IsManager": "FALSE",
"EmployeeNumber": 740132,
"children": []
},
{
"name": "Isacco",
"IsManager": "FALSE",
"EmployeeNumber": 742246,
"children": []
},
{
"name": "Fleurette",
"IsManager": "FALSE",
"EmployeeNumber": 742205,
"children": []
},
{
"name": "Dicky",
"IsManager": "FALSE",
"EmployeeNumber": 742736,
"children": []
},
{
"name": "Wini",
"IsManager": "FALSE",
"EmployeeNumber": 741836,
"children": []
},
{
"name": "Elden",
"IsManager": "FALSE",
"EmployeeNumber": 743234,
"children": []
},
{
"name": "Marjie",
"IsManager": "FALSE",
"EmployeeNumber": 740196,
"children": []
},
{
"name": "Vanna",
"IsManager": "FALSE",
"EmployeeNumber": 738053,
"children": []
},
{
"name": "Emilio",
"IsManager": "FALSE",
"EmployeeNumber": 751901,
"children": []
},
{
"name": "Enrique",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Lilas",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Elita",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Hyacintha",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Markus",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Calhoun",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Melisande",
"IsManager": "FALSE",
"EmployeeNumber": 748847,
"children": []
},
{
"name": "Haroun",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Niles",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Adorne",
"IsManager": "FALSE",
"EmployeeNumber": 724804,
"children": []
},
{
"name": "Dianne",
"IsManager": "FALSE",
"EmployeeNumber": 724863,
"children": []
},
{
"name": "Faye",
"IsManager": "FALSE",
"EmployeeNumber": 732329,
"children": []
},
{
"name": "Tabina",
"IsManager": "FALSE",
"EmployeeNumber": 724910,
"children": []
}
]
},
{
"name": "Spike",
"IsManager": "FALSE",
"EmployeeNumber": 732941,
"children": [
{
"name": "Reta",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Cirillo",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}
]
},
{
"name": "Berty",
"IsManager": "TRUE",
"EmployeeNumber": 726527,
"children": [
{
"name": "Gerrie",
"IsManager": "TRUE",
"EmployeeNumber": 727939,
"children": [
{
"name": "Kelci",
"IsManager": "FALSE",
"EmployeeNumber": 739483,
"children": []
},
{
"name": "Alexandros",
"IsManager": "FALSE",
"EmployeeNumber": 723369,
"children": []
},
{
"name": "Loreen",
"IsManager": "FALSE",
"EmployeeNumber": 746432,
"children": []
},
{
"name": "Cortie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Keven",
"IsManager": "FALSE",
"EmployeeNumber": 723060,
"children": []
},
{
"name": "Shanie",
"IsManager": "FALSE",
"EmployeeNumber": 707562,
"children": []
},
{
"name": "Hatti",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Tammi",
"IsManager": "FALSE",
"EmployeeNumber": 717763,
"children": []
},
{
"name": "Blondell",
"IsManager": "FALSE",
"EmployeeNumber": 731167,
"children": []
}
]
},
{
"name": "Bellina",
"IsManager": "FALSE",
"EmployeeNumber": 731162,
"children": []
},
{
"name": "Constancia",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Dieter",
"IsManager": "FALSE",
"EmployeeNumber": 725942,
"children": []
},
{
"name": "Illa",
"IsManager": "FALSE",
"EmployeeNumber": 733953,
"children": [
{
"name": "Roley",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Talbot",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}
]
},
{
"name": "Theodora",
"IsManager": "TRUE",
"EmployeeNumber": 721734,
"children": [
{
"name": "Ebeneser",
"IsManager": "FALSE",
"EmployeeNumber": 741729,
"children": []
},
{
"name": "Allie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Benita",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Elmira",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Dene",
"IsManager": "FALSE",
"EmployeeNumber": 739572,
"children": []
},
{
"name": "Hamil",
"IsManager": "FALSE",
"EmployeeNumber": 731393,
"children": []
},
{
"name": "Fitzgerald",
"IsManager": "FALSE",
"EmployeeNumber": 710334,
"children": [
{
"name": "Leon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}
]
},
{
"name": "Mignon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Constantina",
"IsManager": "FALSE",
"EmployeeNumber": 744831,
"children": []
},
{
"name": "Alysa",
"IsManager": "FALSE",
"EmployeeNumber": 736292,
"children": []
}
]
}
]
},
{
"name": "Garrik",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Onofredo",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Josefa",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Nan",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Birgit",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Ashlan",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Rod",
"IsManager": "TRUE",
"EmployeeNumber": 726043,
"children": [
{
"name": "Lorie",
"IsManager": "TRUE",
"EmployeeNumber": 711520,
"children": [
{
"name": "Norris",
"IsManager": "FALSE",
"EmployeeNumber": 736426,
"children": []
},
{
"name": "Josefa",
"IsManager": "FALSE",
"EmployeeNumber": 728365,
"children": []
},
{
"name": "Carma",
"IsManager": "FALSE",
"EmployeeNumber": 751153,
"children": []
},
{
"name": "Rozelle",
"IsManager": "FALSE",
"EmployeeNumber": 738418,
"children": []
},
{
"name": "Tine",
"IsManager": "FALSE",
"EmployeeNumber": 721367,
"children": []
},
{
"name": "Ransom",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Hildagarde",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Grant",
"IsManager": "FALSE",
"EmployeeNumber": 712948,
"children": []
}
]
},
{
"name": "Karilynn",
"IsManager": "FALSE",
"EmployeeNumber": 102152,
"children": []
},
{
"name": "Tine",
"IsManager": "FALSE",
"EmployeeNumber": 717285,
"children": []
},
{
"name": "Lenna",
"IsManager": "FALSE",
"EmployeeNumber": 707659,
"children": []
},
{
"name": "Fanni",
"IsManager": "TRUE",
"EmployeeNumber": 102936,
"children": [
{
"name": "Nani",
"IsManager": "FALSE",
"EmployeeNumber": 726746,
"children": []
},
{
"name": "Jethro",
"IsManager": "FALSE",
"EmployeeNumber": 744442,
"children": []
},
{
"name": "Olenka",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Morena",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Susana",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Hammad",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
},
{
"name": "Erwin",
"IsManager": "FALSE",
"EmployeeNumber": 711550,
"children": []
}
]
},
{
"name": "Petr",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}
]
}
]
}
];
generateEmployeeCounts = (person, count) => {
count ? count : count = { tbd: 0, fte: 0 };
if (person && person.children) {
person.children.forEach(child => {
if (child.EmployeeNumber === "TBD") {
count.tbd++;
} else {
count.fte++;
}
generateEmployeeCounts(child.children, count);
});
}
return `Total: ${count.tbd + count.fte}/TBD: ${count.tbd}/FTE: ${count.fte}`;
}
detectManagers = (arr) => {
arr.forEach(person => {
if (person && person.children) {
if (person.children.length > 0) {
person.IsManager = true;
detectManagers(person.children);
} else {
person.IsManager = false;
}
person.count = generateEmployeeCounts(person);
}
});
}
detectManagers(data);
console.log(data);
同样,我建议您重组数据结构,以免嵌套太深。您可能会有一群人。每个人都有一个适用于他们的UID。每个人下面的子级数组将是一个UID数组,用于跟踪管理者关系(子级)。这将消除您嵌套的数据结构。
希望这会有所帮助。
答案 1 :(得分:0)
不确定要问什么,但这是否意味着您想找到每个经理,包括Derived
中的经理?
只需将您的对象放入变量中即可
Base
然后使用此代码查找每个经理:
curl ipconf.cf
答案 2 :(得分:0)
const data = [{
"name": "Wendeline",
"IsManager": "TRUE",
"children": [{
"name": "Goraud",
"IsManager": "TRUE",
"EmployeeNumber": 706997,
"children": [{
"name": "Mersey",
"IsManager": "FALSE",
"EmployeeNumber": 102752,
"children": []
}, {
"name": "Elli",
"IsManager": "FALSE",
"EmployeeNumber": 742047,
"children": [{
"name": "Hans",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Bald",
"IsManager": "FALSE",
"EmployeeNumber": 741064,
"children": []
}, {
"name": "Truda",
"IsManager": "FALSE",
"EmployeeNumber": 739162,
"children": []
}, {
"name": "Matty",
"IsManager": "FALSE",
"EmployeeNumber": 717067,
"children": []
}, {
"name": "Ola",
"IsManager": "TRUE",
"EmployeeNumber": 713122,
"children": [{
"name": "Frankie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Quint",
"IsManager": "FALSE",
"EmployeeNumber": 705616,
"children": []
}, {
"name": "Georgi",
"IsManager": "FALSE",
"EmployeeNumber": 733001,
"children": []
}, {
"name": "Danie",
"IsManager": "FALSE",
"EmployeeNumber": 742962,
"children": []
}, {
"name": "Judon",
"IsManager": "FALSE",
"EmployeeNumber": 750620,
"children": []
}, {
"name": "Nellie",
"IsManager": "FALSE",
"EmployeeNumber": 101490,
"children": []
}, {
"name": "Marji",
"IsManager": "FALSE",
"EmployeeNumber": 705660,
"children": []
}, {
"name": "Adelaida",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Bing",
"IsManager": "FALSE",
"EmployeeNumber": 745205,
"children": []
}, {
"name": "Odilia",
"IsManager": "FALSE",
"EmployeeNumber": 718622,
"children": []
}]
}, {
"name": "Bernardina",
"IsManager": "FALSE",
"EmployeeNumber": 726710,
"children": []
}, {
"name": "Myca",
"IsManager": "FALSE",
"EmployeeNumber": 726163,
"children": []
}, {
"name": "Husain",
"IsManager": "FALSE",
"EmployeeNumber": 728267,
"children": []
}, {
"name": "Cristie",
"IsManager": "FALSE",
"EmployeeNumber": 750267,
"children": []
}, {
"name": "Nikolai",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "James",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Ashbey",
"IsManager": "FALSE",
"EmployeeNumber": 744719,
"children": []
}, {
"name": "Flss",
"IsManager": "FALSE",
"EmployeeNumber": 746709,
"children": []
}, {
"name": "Felisha",
"IsManager": "FALSE",
"EmployeeNumber": 739945,
"children": [{
"name": "Zelig",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Jakob",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}]
}, {
"name": "Cointon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Jo",
"IsManager": "TRUE",
"EmployeeNumber": 716884,
"children": [{
"name": "Sylvia",
"IsManager": "FALSE",
"EmployeeNumber": 744160,
"children": []
}, {
"name": "Vicki",
"IsManager": "FALSE",
"EmployeeNumber": 735637,
"children": []
}, {
"name": "Blanche",
"IsManager": "FALSE",
"EmployeeNumber": 729407,
"children": []
}, {
"name": "Mirabelle",
"IsManager": "FALSE",
"EmployeeNumber": 731551,
"children": []
}, {
"name": "Floria",
"IsManager": "FALSE",
"EmployeeNumber": 727255,
"children": []
}, {
"name": "Flossie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Anny",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hyatt",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Juli",
"IsManager": "FALSE",
"EmployeeNumber": 740132,
"children": []
}, {
"name": "Isacco",
"IsManager": "FALSE",
"EmployeeNumber": 742246,
"children": []
}, {
"name": "Fleurette",
"IsManager": "FALSE",
"EmployeeNumber": 742205,
"children": []
}, {
"name": "Dicky",
"IsManager": "FALSE",
"EmployeeNumber": 742736,
"children": []
}, {
"name": "Wini",
"IsManager": "FALSE",
"EmployeeNumber": 741836,
"children": []
}, {
"name": "Elden",
"IsManager": "FALSE",
"EmployeeNumber": 743234,
"children": []
}, {
"name": "Marjie",
"IsManager": "FALSE",
"EmployeeNumber": 740196,
"children": []
}, {
"name": "Vanna",
"IsManager": "FALSE",
"EmployeeNumber": 738053,
"children": []
}, {
"name": "Emilio",
"IsManager": "FALSE",
"EmployeeNumber": 751901,
"children": []
}, {
"name": "Enrique",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Lilas",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Elita",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hyacintha",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Markus",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Calhoun",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Melisande",
"IsManager": "FALSE",
"EmployeeNumber": 748847,
"children": []
}, {
"name": "Haroun",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Niles",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Adorne",
"IsManager": "FALSE",
"EmployeeNumber": 724804,
"children": []
}, {
"name": "Dianne",
"IsManager": "FALSE",
"EmployeeNumber": 724863,
"children": []
}, {
"name": "Faye",
"IsManager": "FALSE",
"EmployeeNumber": 732329,
"children": []
}, {
"name": "Tabina",
"IsManager": "FALSE",
"EmployeeNumber": 724910,
"children": []
}]
}, {
"name": "Spike",
"IsManager": "FALSE",
"EmployeeNumber": 732941,
"children": [{
"name": "Reta",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Cirillo",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Berty",
"IsManager": "TRUE",
"EmployeeNumber": 726527,
"children": [{
"name": "Gerrie",
"IsManager": "TRUE",
"EmployeeNumber": 727939,
"children": [{
"name": "Kelci",
"IsManager": "FALSE",
"EmployeeNumber": 739483,
"children": []
}, {
"name": "Alexandros",
"IsManager": "FALSE",
"EmployeeNumber": 723369,
"children": []
}, {
"name": "Loreen",
"IsManager": "FALSE",
"EmployeeNumber": 746432,
"children": []
}, {
"name": "Cortie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Keven",
"IsManager": "FALSE",
"EmployeeNumber": 723060,
"children": []
}, {
"name": "Shanie",
"IsManager": "FALSE",
"EmployeeNumber": 707562,
"children": []
}, {
"name": "Hatti",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Tammi",
"IsManager": "FALSE",
"EmployeeNumber": 717763,
"children": []
}, {
"name": "Blondell",
"IsManager": "FALSE",
"EmployeeNumber": 731167,
"children": []
}]
}, {
"name": "Bellina",
"IsManager": "FALSE",
"EmployeeNumber": 731162,
"children": []
}, {
"name": "Constancia",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Dieter",
"IsManager": "FALSE",
"EmployeeNumber": 725942,
"children": []
}, {
"name": "Illa",
"IsManager": "FALSE",
"EmployeeNumber": 733953,
"children": [{
"name": "Roley",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Talbot",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Theodora",
"IsManager": "TRUE",
"EmployeeNumber": 721734,
"children": [{
"name": "Ebeneser",
"IsManager": "FALSE",
"EmployeeNumber": 741729,
"children": []
}, {
"name": "Allie",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Benita",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Elmira",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Dene",
"IsManager": "FALSE",
"EmployeeNumber": 739572,
"children": []
}, {
"name": "Hamil",
"IsManager": "FALSE",
"EmployeeNumber": 731393,
"children": []
}, {
"name": "Fitzgerald",
"IsManager": "FALSE",
"EmployeeNumber": 710334,
"children": [{
"name": "Leon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}, {
"name": "Mignon",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Constantina",
"IsManager": "FALSE",
"EmployeeNumber": 744831,
"children": []
}, {
"name": "Alysa",
"IsManager": "FALSE",
"EmployeeNumber": 736292,
"children": []
}]
}]
}, {
"name": "Garrik",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Onofredo",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Josefa",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Nan",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Birgit",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Ashlan",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Rod",
"IsManager": "TRUE",
"EmployeeNumber": 726043,
"children": [{
"name": "Lorie",
"IsManager": "TRUE",
"EmployeeNumber": 711520,
"children": [{
"name": "Norris",
"IsManager": "FALSE",
"EmployeeNumber": 736426,
"children": []
}, {
"name": "Josefa",
"IsManager": "FALSE",
"EmployeeNumber": 728365,
"children": []
}, {
"name": "Carma",
"IsManager": "FALSE",
"EmployeeNumber": 751153,
"children": []
}, {
"name": "Rozelle",
"IsManager": "FALSE",
"EmployeeNumber": 738418,
"children": []
}, {
"name": "Tine",
"IsManager": "FALSE",
"EmployeeNumber": 721367,
"children": []
}, {
"name": "Ransom",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hildagarde",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Grant",
"IsManager": "FALSE",
"EmployeeNumber": 712948,
"children": []
}]
}, {
"name": "Karilynn",
"IsManager": "FALSE",
"EmployeeNumber": 102152,
"children": []
}, {
"name": "Tine",
"IsManager": "FALSE",
"EmployeeNumber": 717285,
"children": []
}, {
"name": "Lenna",
"IsManager": "FALSE",
"EmployeeNumber": 707659,
"children": []
}, {
"name": "Fanni",
"IsManager": "TRUE",
"EmployeeNumber": 102936,
"children": [{
"name": "Nani",
"IsManager": "FALSE",
"EmployeeNumber": 726746,
"children": []
}, {
"name": "Jethro",
"IsManager": "FALSE",
"EmployeeNumber": 744442,
"children": []
}, {
"name": "Olenka",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Morena",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Susana",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Hammad",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}, {
"name": "Erwin",
"IsManager": "FALSE",
"EmployeeNumber": 711550,
"children": []
}]
}, {
"name": "Petr",
"IsManager": "FALSE",
"EmployeeNumber": "TBD",
"children": []
}]
}]
}];
function addCounts(users = []) {
for (const user of users) {
if (user.IsManager === 'TRUE') {
const count = countChildren(user.children);
user.count = `${count.total}/${count.tbd}TBD/${count.fte}FTE`;
}
user.children = addCounts(user.children);
}
return users;
}
function countChildren(children = []) {
const count = {
total: 0,
fte: 0,
tbd: 0
};
for (const child of children) {
count.total++;
if (child.EmployeeNumber === 'TBD') {
count.tbd++;
} else {
count.fte++;
}
const childrenCount = countChildren(child.children);
count.tbd += childrenCount.tbd;
count.fte += childrenCount.fte;
count.total += childrenCount.total;
}
return count;
}
console.log(addCounts(data));