不知道这个递归是哪块出了问题,这个方法总是获取空数组?
const findOperate = (arr = [], menuName) => {
let res = []
for (let i = 0; i < arr.length; i++) {
if (arr[i].name === menuName) {
res = arr[i].operation_list
break
} else {
if (arr[i].menu_list.length) {
findOperate(arr[i].menu_list, menuName)
}
}
}
return res
}
findOperate(arr, '系统管理员')
const arr = [
{
"id": "169880657983438848",
"code": "systemConfig",
"name": "系统配置管理",
"route": "/systemConfig",
"description": "系统配置管理",
"menu_list": [],
"operation_list": [
{
"id": "170594677588754432",
"code": "add",
"name": "新增",
"description": ""
},
{
"id": "170594694908084224",
"code": "edit",
"name": "编辑",
"description": ""
},
{
"id": "170594706926862336",
"code": "delete",
"name": "删除",
"description": ""
}
]
},
{
"id": "169880805688999936",
"code": "userManage",
"name": "系统用户管理",
"route": "",
"description": "系统用户管理菜单",
"menu_list": [
{
"id": "169880863841976320",
"code": "adminManage",
"name": "系统管理员",
"route": "/adminManage",
"description": "系统管理员菜单",
"menu_list": [],
"operation_list": [
{
"id": "170594813441212416",
"code": "add",
"name": "新增",
"description": ""
},
{
"id": "170594834417975296",
"code": "edit",
"name": "编辑",
"description": ""
},
{
"id": "170594849289928704",
"code": "disable",
"name": "停用",
"description": ""
},
{
"id": "170595468132220928",
"code": "resetPassword",
"name": "重置密码",
"description": ""
},
{
"id": "170801863500759040",
"code": "enable",
"name": "启用",
"description": ""
}
]
},
{
"id": "169880911479832576",
"code": "masterManage",
"name": "专家",
"route": "/masterManage",
"description": "专家菜单",
"menu_list": [],
"operation_list": [
{
"id": "170594872555732992",
"code": "add",
"name": "新增",
"description": ""
},
{
"id": "170594885485723648",
"code": "edit",
"name": "编辑",
"description": ""
},
{
"id": "170594898276253696",
"code": "disable",
"name": "停用",
"description": ""
},
{
"id": "170595499383980032",
"code": "resetPassword",
"name": "重置密码",
"description": ""
},
{
"id": "170801897956966400",
"code": "enable",
"name": "启用",
"description": ""
}
]
},
{
"id": "169880942211497984",
"code": "personManage",
"name": "学员",
"route": "/personManage",
"description": "学员菜单",
"menu_list": [],
"operation_list": [
{
"id": "170594919992262656",
"code": "add",
"name": "新增",
"description": ""
},
{
"id": "170594932861435904",
"code": "edit",
"name": "编辑",
"description": ""
},
{
"id": "170594945705443328",
"code": "disable",
"name": "停用",
"description": ""
},
{
"id": "170595520110133248",
"code": "resetPassword",
"name": "重置密码",
"description": ""
},
{
"id": "170801931430658048",
"code": "enable",
"name": "启用",
"description": ""
}
]
}
],
"operation_list": []
},
{
"id": "169881001833529344",
"code": "projectTrain",
"name": "项目培训管理",
"route": "",
"description": "项目培训管理菜单",
"menu_list": [
{
"id": "169881081221218304",
"code": "projectManage",
"name": "项目管理",
"route": "/projectManage",
"description": "项目管理菜单",
"menu_list": [],
"operation_list": [
{
"id": "170594987126292480",
"code": "add",
"name": "新增",
"description": ""
},
{
"id": "170595004892315648",
"code": "edit",
"name": "编辑",
"description": ""
},
{
"id": "170595020011732992",
"code": "delete",
"name": "删除",
"description": ""
},
{
"id": "170595099047100416",
"code": "trainImport",
"name": "批量导入培训",
"description": ""
}
]
},
{
"id": "169881144667406336",
"code": "trainManage",
"name": "培训管理",
"route": "/trainManage",
"description": "培训管理菜单",
"menu_list": [],
"operation_list": [
{
"id": "170595119011987456",
"code": "add",
"name": "新增",
"description": ""
},
{
"id": "170595131858092032",
"code": "edit",
"name": "编辑",
"description": ""
},
{
"id": "170595142873382912",
"code": "delete",
"name": "删除",
"description": ""
},
{
"id": "170595163668742144",
"code": "trainCourse",
"name": "课程列表",
"description": ""
},
{
"id": "170595186249826304",
"code": "trainPerson",
"name": "学员列表",
"description": ""
}
]
},
{
"id": "169881182098423808",
"code": "courseManage",
"name": "课程库",
"route": "/courseManage",
"description": "课程库菜单",
"menu_list": [],
"operation_list": [
{
"id": "170595312643080192",
"code": "add",
"name": "新增",
"description": ""
},
{
"id": "170595323860746240",
"code": "edit",
"name": "编辑",
"description": ""
},
{
"id": "170595335360479232",
"code": "delete",
"name": "删除",
"description": ""
}
]
}
],
"operation_list": []
},
{
"id": "169881236203896832",
"code": "dataAnalysis",
"name": "项目培训统计",
"route": "",
"description": "项目培训统计菜单",
"menu_list": [
{
"id": "169881284272717824",
"code": "projectAnalysis",
"name": "项目统计",
"route": "/projectAnalysis",
"description": "项目统计菜单",
"menu_list": [],
"operation_list": [
{
"id": "170595379336708096",
"code": "export",
"name": "导出",
"description": ""
}
]
},
{
"id": "169881324465684480",
"code": "trainAnalysis",
"name": "培训统计",
"route": "/trainAnalysis",
"description": "培训统计菜单",
"menu_list": [],
"operation_list": [
{
"id": "170595397435129856",
"code": "export",
"name": "导出",
"description": ""
}
]
},
{
"id": "169881363680329728",
"code": "personAnalysis",
"name": "学员统计",
"route": "/personAnalysis",
"description": "学员统计菜单",
"menu_list": [],
"operation_list": [
{
"id": "170595413102952448",
"code": "export",
"name": "导出",
"description": ""
}
]
}
],
"operation_list": []
}
]