On Array data processing

const routes = [

]
{
  path: "/",
  name: "home",
  meta: {
    title: "",
    icon: "el-icon-menu",
    hide: true
  },
},
{
  path: "/monitor",
  name: "",
  meta: {
    title: "",
    hide: true
  },
  children: [
    {
      path: "/monitor/pass",
      name: "",
      meta: {
        title: "",
        hide: true
      }
    },
    {
      path: "/monitor/rules",
      name: "",
      meta: {
        title: "",
        hide: true
      }
    }
  ]
},
{
  path: "/blacklist",
  name: "",
  meta: {
    title: "",
    hide: true
  },
  children: [
    {
      path: "/blacklist/id-card",
      name: "",
      meta: {
        title: "",
        hide: true
      }
    },
    {
      path: "/blacklist/companyName",
      name: "",
      meta: {
        title: "",
        hide: true
      }
    },
    {
      path: "/blacklist/companyPhone",
      name: "",
      meta: {
        title: "",
        hide: true
      }
    },
  ]
},
{
  path: "/bairongLoaning",
  name: "",
  meta: {
    title: "",
    icon: "el-icon-view",
    hide: true
  }
}

],

const permission = ["homepage", "personnel list management", "setting parameters", "setting status"];
menu rendering is based on the title field in the meta of routes above. Now the scene is that the menu may have only one-level menu, or there may be a second-level menu, or there may be more. My menu is recursively rendered
, and now I want to control the hide field of meta in routes according to this permission array. If there is this permission in permission, set the hide of the meta of this menu to false.
then if it corresponds to the second-level menu, that is, in children, set the hide of this item.children.meta to false, and its parent menu also shows
how to write it is easy-sharp-sharp-sharp problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Jun.27,2022

< H1 > remember, the habit of reaching out for the hand needs to be changed < / H1 >

because of uncertain levels, the best solution is recursion;

because the array is a reference type, route is not reassigned in recursion.

let route = [
    {
      path: '/',
      name: 'home',
      meta: {
        title: '',
        icon: 'el-icon-menu',
        hide: true
      },
    },
    {
      path: '/monitor',
      name: '',
      meta: {
        title: '',
        hide: true
      },
      children: [
        {
          path: '/monitor/pass',
          name: '',
          meta: {
            title: '',
            hide: true
          }
        },
        {
          path: '/monitor/rules',
          name: '',
          meta: {
            title: '',
            hide: true
          }
        }
      ]
    },
    {
      path: '/blacklist',
      name: '',
      meta: {
        title: '',
        hide: true
      },
      children: [
        {
          path: '/blacklist/id-card',
          name: '',
          meta: {
            title: '',
            hide: true
          }
        },
        {
          path: '/blacklist/companyName',
          name: '',
          meta: {
            title: '',
            hide: true
          }
        },
        {
          path: '/blacklist/companyPhone',
          name: '',
          meta: {
            title: '',
            hide: true
          }
        },
      ]
    },
    {
      path: '/bairongLoaning',
      name: '',
      meta: {
        title: '',
        icon: 'el-icon-view',
        hide: true
      }
    }
]

const permission = ['', '','',''];

function checkPermission(route, parent = null) {
    for (let item of route) {
        if (item.children && item.children.length > 0) {
            checkPermission(item.children, item)
        } else {
            item.meta.hide = !permission.includes(item.name)
            if (parent && permission.includes(item.name) && parent.meta.hide) {
                parent.meta.hide = false
            }
        }
    }
}

checkPermission(route)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9ab76-68f6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9ab76-68f6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?