前端 递归

39 阅读1分钟
function *** (){
   const allData = []
   const loop = (data = []) => {
      data.forEach(it => {
        if (it.children?.length) {
          loop(it.children)
        }
        allData.push({
          ...it,
        })
      })
    }
    loop(item.children)
}