• map 、new Set、[...] 、 filter用法


     var data = [    
            {
                "StepName":"送拟稿部门初审",
                "Label":"送拟稿部门初审",
                "NeedUser":true,
                "AllowSelect":true,
                "AllowFree":false,
                "OnlySingleSel":false,
                "AutoSelectAll":false,
                "Visible":false,
                "OrderIndex":0,
                "WorkFlowXml":"本部门初审",
                "Users":[
                    {
                        "ID":"06f0d6c4-d42a-46d6-82f3-4080c889499d",
                        "Name":"朱晓明",
                        "OrgId":"8d9ce4c0-8d11-4027-af9d-0fe37fe540d1",
                        "OrgName":"信息管理中心IT建设与应用部",
                        "Rank":"999",
                        "RoleDeptID":null,
                        "RoleDeptName":null,
                        "ParallelKey":"",
                        "ParallelLabel":""
                    },
                    {
                        "ID":"17372b4c-d922-4507-a662-756fbd4fabf4",
                        "Name":"大宋",
                        "OrgId":"8d9ce4c0-8d11-4027-af9d-0fe37fe540d1",
                        "OrgName":"信息管理中心",
                        "Rank":"999",
                        "RoleDeptID":null,
                        "RoleDeptName":null,
                        "ParallelKey":"",
                        "ParallelLabel":""
                    },
                    {
                        "ID":"1adc4150-1772-4df9-849b-5c28c5103d37",
                        "Name":"罗志祥",
                        "OrgId":"8d9ce4c0-8d11-4027-af9d-0fe37fe540d1",
                        "OrgName":"集团公司",
                        "Rank":"999",
                        "RoleDeptID":null,
                        "RoleDeptName":null,
                        "ParallelKey":"",
                        "ParallelLabel":""
                    },
                ]
            },
            {
                "StepName":"拟稿本部门部门经理/部门领导审稿",
                "Label":"拟稿本部门部门经理/部门领导审稿",
                "NeedUser":true,
                "AllowSelect":true,
                "AllowFree":false,
                "OnlySingleSel":false,
                "AutoSelectAll":false,
                "Visible":false,
                "OrderIndex":0,
                "WorkFlowXml":"本部门部门经理审稿",
                "Users":[
                    {
                        "ID":"bd15c9ff-acee-474b-91d3-e379b5a01910",
                        "Name":"杨幂",
                        "OrgId":"8d9ce4c0-8d11-4027-af9d-0fe37fe540d1",
                        "OrgName":"信息管理中心IT建设与应用部",
                        "Rank":"1",
                        "RoleDeptID":null,
                        "RoleDeptName":null,
                        "ParallelKey":"",
                        "ParallelLabel":""
                    },
                    {
                        "ID":"b1c6f539-85fa-4008-ad47-10972d5bfc09",
                        "Name":"娜扎",
                        "OrgId":"8d9ce4c0-8d11-4027-af9d-0fe37fe540d1",
                        "OrgName":"信息管理中心IT建设与应用部",
                        "Rank":"2",
                        "RoleDeptID":null,
                        "RoleDeptName":null,
                        "ParallelKey":"",
                        "ParallelLabel":""
                    },
                    {
                        "ID":"0f7c2a11-fc32-46c7-b618-cced5ccb170e",
                        "Name":"迪丽热巴",
                        "OrgId":"8d9ce4c0-8d11-4027-af9d-0fe37fe540d1",
                        "OrgName":"党群综合部",
                        "Rank":"3",
                        "RoleDeptID":null,
                        "RoleDeptName":null,
                        "ParallelKey":"",
                        "ParallelLabel":""
                    }
                ]
            }
        ];   
            data.forEach(i => {  //把两层数据 拆分三层数据   第为二层为部门层
                var orgNameLi = i.Users
                console.log('*******', orgNameLi);
                var orgNameList = orgNameLi.map(item=>item.OrgName)//按部门分类
                console.log('jjj',orgNameList)
                let tmpList = new Set(orgNameList)   //去重
                console.log('kkk',tmpList)
                let arrList = [...tmpList]  //转换成数组
                console.log('lll',arrList)
                if(arrList.length){
                    for(let orgName of arrList){
                        let orgPeople = orgNameLi.filter(item=>item.OrgName == orgName) //数据筛选 部门相同 则给到orgPeople
                        console.log('jshs',orgPeople)
                    }
                }
            });           

    结果为:

  • 相关阅读:
    多线程下的调用上下文 : CallContext
    MongoDB入门实战教程(7)
    MongoDB入门实战教程(6)
    MongoDB入门实战教程(5)
    MongoDB入门实战教程(4)
    MongoDB入门实战教程(3)
    MongoDB入门实战教程(2)
    MongoDB入门实战教程(1)
    ASP.NET 5 with Dapr 初体验
    2021成都.NET开发者Connect线下活动
  • 原文地址:https://www.cnblogs.com/chchchc/p/12774055.html
Copyright © 2020-2023  润新知