• js 列表分组处理


     getList(){
         let data=[
           {
             workflowDefinitionId:'workflowDefinitionId',
             name:'退款申请',
             state:1,
             bpmnId:'tk',
             useObj:1,
             typeCode:'01',
             typeName:'财务类'
           },
            {
             workflowDefinitionId:'workflowDefinitionId',
             name:'暂停/恢复商家返款(分成)申请',
             state:1,
             bpmnId:'sq',
             useObj:1,
             typeCode:'01',
             typeName:'财务类'
           },
            {
             workflowDefinitionId:'workflowDefinitionId',
             name:'返款账户变更申请',
             state:1,
             bpmnId:'fk',
             useObj:1,
             typeCode:'01',
             typeName:'财务类'
           },
              {
             workflowDefinitionId:'workflowDefinitionId',
             name:'网点冲洗账号申请',
             state:1,
             bpmnId:'wdsq',
             useObj:1,
             typeCode:'02',
             typeName:'运营类'
           },
              {
             workflowDefinitionId:'workflowDefinitionId',
             name:'文案申请',
             state:1,
             bpmnId:'wasj',
             useObj:1,
             typeCode:'02',
             typeName:'运营类'
           },
           {
             workflowDefinitionId:'workflowDefinitionId',
             name:'网点撤站申请',
             state:1,
             bpmnId:'czsj',
             useObj:1,
             typeCode:'03',
             typeName:'售后类'
           },
              {
             workflowDefinitionId:'workflowDefinitionId',
             name:'网点免洗活动申请',
             state:1,
             bpmnId:'wdmx',
             useObj:1,
             typeCode:'03',
             typeName:'售后类'
           }
         ]
    
            let newArr = []
              //通过forEach循环数组
              data.forEach((item, i) => {
                let index = -1
                //然后在跑到这里筛选 根据不同的时间放置不同的数组    some()用来查找数组中是否存在某个值  如果存在 就return true
                let isExists = newArr.some((newItem, j) => {
                  if (item.typeCode === newItem.typeCode) {
                    index = j
                    return true
                  }
                })
                //代码是先跑这里的if条件判读
                if (!isExists) {
                  newArr.push({
                    typeCode: item.typeCode,
                    list: [item],
                    typeName: item.typeName,
                    title:item.typeName,
                  })
                } else {
                  newArr[index].list.push(item);
                }
              })
          this.showData=newArr;
          console.log(newArr,"newArr")
        },

    实现效果如下图

     

  • 相关阅读:
    建立适当的索引
    Windows 10Bash命令
    代码生成工具介绍和使用
    分布式的任务调度框架
    Net分布式系统
    Keepalived+LVS+Nginx负载均衡之高可用
    call,apply,bind
    2015搜狐在线笔试题(内存泄露问题)(转)
    十步完全理解SQL(转)
    Linux shell用法和技巧(转)
  • 原文地址:https://www.cnblogs.com/xiaohuasan/p/16044158.html
Copyright © 2020-2023  润新知