let data = [
{exist: "false", appId: "1", name: "组织管理1", menuId: 1, id: 1, type: "menu", parentId: "root"},
{exist: "false", appId: "1", name: "组织管理2", menuId: 2, id: 2, type: "menu", parentId: "root"},
{exist: "false", appId: "1", name: "组织管理3", menuId: 3, id: 3, type: "menu", parentId: "root"},
{exist: "false", appId: "1", name: "组织管理4", menuId: 4, id: 4, type: "menu", parentId: "1"},
{exist: "false", appId: "1", name: "组织管理5", menuId: 5, id: 5, type: "menu", parentId: "1"},
{exist: "false", appId: "1", name: "组织管理6", menuId: 6, id: 6, type: "menu", parentId: "5"},
{exist: "false", appId: "1", name: "组织管理7", menuId: 7, id: 7, type: "menu", parentId: "5"},
{exist: "false", appId: "1", name: "组织管理8", menuId: 8, id: 8, type: "menu", parentId: "7"},
{exist: "false", appId: "1", name: "组织管理9", menuId: 9, id: 9, type: "menu", parentId: "3"},
{exist: "false", appId: "1", name: "组织管理9", menuId: 13, id: 13, type: "menu", parentId: "3"},
{exist: "false", appId: "1", name: "组织管理10", menuId: 10, id: 10, type: "button", parentId: "1"},
{exist: "false", appId: "1", name: "组织管理11", menuId: 11, id: 11, type: "button", parentId: "1"},
{exist: "false", appId: "1", name: "组织管理12", menuId: 12, id: 12, type: "button", parentId: "5"},
];
this.typeMenu = data.filter(item => item['type'] === 'menu'); this.typeButton = data.filter(item => item['type'] === 'button'); this.typeMenu.forEach(item => { item['childMenu'] = []; item['childButton'] = [] this.typeMenu.forEach(item1 => { if (Number(item1['parentId']) === Number(item['id'])) { item['childMenu'].push(item1); } }); this.typeButton.forEach(item2 => { if (Number(item2['parentId']) === Number(item['id'])) { item['childButton'].push(item2); } }); }) this.typeMenu = this.typeMenu.filter(item => item['parentId'] === 'root'); result = this.typeMenu;