Filter tree: get the children of the corresponding tree node

 data is tree value, code is id

 /** @description 拿到对应树节点的children */
    getTreeItem(data, code) {
      let result
      let hasFound = false
      const fn = function(data, code) {
        for (let i = 0; i < data.length; i++) {
          if (data[i].id === code && !hasFound) {
            result = data[i].children
            hasFound = true
          } else if (data[i].children && data[i].children.length > 0) {
            fn(data[i].children, code)
          }
        }
      }
      fn(data, code)
      return result
    },

Guess you like

Origin blog.csdn.net/Blue54/article/details/129689100