数据结构

    1. arr: [
    2. { id: 1, icon: "user", name: "张安", hidden: true },
    3. {
    4. id: 2,
    5. icon: null,
    6. name: "张三",
    7. hidden: false,
    8. children: [
    9. {
    10. id: 4,
    11. name: "张三2",
    12. icon: "",
    13. type: 0,
    14. level: 1,
    15. },
    16. {
    17. id: 5,
    18. name: "张三3",
    19. icon: "",
    20. type: 0,
    21. level: 2,
    22. },
    23. ],
    24. },
    25. ],

    js代码

    1. let newarr = [];
    2. this.arr.forEach((v, index) => {
    3. newarr.push({
    4. index: v.index,
    5. name: v.name,
    6. });
    7. if (v.children && v.children.length > 0) {
    8. let dd = [];
    9. v.children.forEach((item) => {
    10. dd.push({
    11. index: item.id,
    12. name: item.name,
    13. });
    14. });
    15. newarr[index].children = dd;
    16. }
    17. });

    运行结果
    image.png