树结构 数据 遍历children形式数据

样式图:

    /**
     * 遍历children形式数据
     * @param data 需要遍历的数组
     * @param callback 回调
     * @param childKey children字段名
     */
   eachTreeData(data, callback, childKey) {
      if (!childKey) childKey = 'children'
      data.forEach(d => {
        if (callback(d) !== false && d[childKey]) this.eachTreeData(d[childKey], callback, childKey)
      })
    }

使用:

      this.eachTreeData('遍历数据', data => {
            console.log(data)
      })

猜你喜欢

转载自blog.csdn.net/weixin_65478269/article/details/131081115