Skip to content

deep

js
deep(data, fieldNames)

获取树型数据最深层级

参数

名称说明类型默认值
data数据列表array-
fieldNames字段名object{ children: 'children' }

代码演示

基础用法

js
const data = [
  {
    id: '1',
    title: '选项1',
    children: [
      {
        id: '1-1',
        title: '选项1-1',
        children: [
          {
            id: '1-1-1',
            title: '选项1-1-1'
          }
        ]
      },
      {
        id: '1-2',
        title: '选项1-2',
      }
    ]
  },
  {
    id: '2',
    title: '选项2',
    children: [
      {
        id: '2-1',
        title: '选项2-1',
      },
      {
        id: '2-2',
        title: '选项2-2',
      }
    ]
  }
]

const count = deep(data)
json
3

本文档内容版权为 XYAdmin 作者所有,保留所有权利。