递归过滤树结构数据

export function getCurrentMenu(dataList, roleList){
  let menu = dataList.filter(item =>{
    console.log(roleList.indexOf(item.name) !== -1)
    if(roleList.indexOf(item.name) !== -1){
      if(item.children){
          //递归循环
          item.children=getCurrentMenu(item.children,roleList)
      }
      return item
    }
  })
  return menu
}

  

posted @ 2022-08-03 19:20  不服憋着  阅读(109)  评论(0编辑  收藏  举报