js使用广度优先给树形结构添加level

  const getStockTableColumns = () => {
    const columns = [
      {
        title: '',
        children: [
          {
            title: '基础信息',
            children: [
              { title: '公司', dataIndex: 'COMPANY_NAME', key: 'COMPANY_NAME', width: 180 },
              { title: '品牌', dataIndex: 'NC_BRAND_NO', key: 'NC_BRAND_NO', width: 120 },
              { title: '年份', dataIndex: 'YEAR_NAME', key: 'YEAR_NAME', width: 120 },
              { title: '季节', dataIndex: 'SEASON_NAME', key: 'SEASON_NAME', width: 120 },
            ],
          },
        ],
      },
      {
        title: 'A)POS 系统数字',
        children: [
          {
            title: '鞋',
            children: [
              { title: '数量', dataIndex: 'I41qty', key: 'I41qty', width: 120 },
              { title: '金额', dataIndex: 'I41amount', key: 'I41amount', width: 120 },
            ],
          },
          {
            title: '服',
            children: [
              { title: '数量', dataIndex: 'I46qty', key: 'I46qty', width: 120 },
              { title: '金额', dataIndex: 'I46amount', key: 'I46amount', width: 120 },
            ],
          },
          {
            title: '配',
            children: [
              { title: '数量', dataIndex: 'I47qty', key: 'I47qty', width: 120 },
              { title: '金额', dataIndex: 'I47amount', key: 'I47amount', width: 120 },
            ],
          },
          {
            title: '总数',
            children: [
              { title: '数量', dataIndex: 'Iqtytotal', key: 'Iqtytotal', width: 120 },
              { title: '金额', dataIndex: 'Iamounttotal', key: 'Iamounttotal', width: 120 },
            ],
          },
        ],
      },
      {
        title: 'B)调整批发退货及在途货品',
        children: [
          {
            title: '鞋',
            children: [
              { title: '数量', dataIndex: 'A41qty', key: 'A41qty', width: 120 },
              { title: '金额', dataIndex: 'A41amount', key: 'A41amount', width: 120 },
            ],
          },
          {
            title: '服',
            children: [
              { title: '数量', dataIndex: 'A46qty', key: 'A46qty', width: 120 },
              { title: '金额', dataIndex: 'A46amount', key: 'A46amount', width: 120 },
            ],
          },
          {
            title: '配',
            children: [
              { title: '数量', dataIndex: 'A47qty', key: 'A47qty', width: 120 },
              { title: '金额', dataIndex: 'A47amount', key: 'A47amount', width: 120 },
            ],
          },
          {
            title: '总数',
            children: [
              { title: '数量', dataIndex: 'Aqtytotal', key: 'Aqtytotal', width: 120 },
              { title: '金额', dataIndex: 'Aamounttotal', key: 'Aamounttotal', width: 120 },
            ],
          },
        ],
      },
    ]

    return columns
  }

  // 广度遍历, 创建一个执行队列, 当队列为空的时候则结束
  function getName2(data) {
    let result = []
    let level = 0
    let queue = data
    while (queue.length > 0) {
      level += 1
      ;[...queue].forEach((child, i) => {
        queue.shift()
        child.index = i
        child.level = level
        result = result.concat([child])
        child.children && queue.push(...child.children)
      })
    }
    return result 
  }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值