IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> 2022-js-过滤两个对象数组相同元素 -> 正文阅读

[游戏开发]2022-js-过滤两个对象数组相同元素

之前写代码,老是是有这样子的需求,就是编辑返回来的数据和总部的数据,是有些重复的,所以需要过滤编辑返回回来的数据,减去总部返回的数据

let arr1 = [{goods_id: 1, name: 'GPD1420220311171943AAA'}, {goods_id: 2, name: 'GPD1420220311171943BBB'}, {goods_id: 3, name: 'GPD1420220311171943CCC'}, {goods_id: 4, name: 'GPD1420220311171943DDD'}]
let arr2 = [{goods_id: 2, name: 'GPD1420220311171943BBB'}, {goods_id: 3, name: 'GPD1420220311171943CCC'}]
let newArr = []

arr2.forEach(item => {
   newArr.push(item.goods_id)
 })
 for (let goods_id of newArr) {
   arr1 = arr1.filter(item => {
     return goods_id !== item.goods_id
   })
 }
 console.log(arr)
 //得到[{goods_id: 1, name: 'GPD1420220311171943AAA'}, {goods_id: 4, name: 'GPD1420220311171943DDD'}]`

这个是模拟简单的情况下

现在我们来看看真实的情况下的应用

{
    "code":0,
    "message":"操作成功",
    "data":{
        "data":{
            "id":418,
            "cuid":14,
            "branch_id":60,
            "dm_id":97,
            "apm_id":197,
            "storage_id":33,
            "supplier_id":null,
            "supplier_title":null,
            "cca_id":null,
            "cor_id":408,
            "type":1,
            "donor":1,
            "order_no":"GPD1420220311171943",
            "code":null,
            "status":4,
            "amount":"0.00",
            "has_pay":"0.00",
            "payed":"0.00",
            "amount_invoice":"0.00",
            "ratio":null,
            "finish":null,
            "storage_time":"2022-03-11",
            "remark":"范德萨发的",
            "address":"福建福州",
            "address_donor":null,
            "order_no_donor":null,
            "payment_type":null,
            "project_manager_id":327,
            "creator":327,
            "handler":327,
            "step_id":0,
            "update_time":"2022-03-11 17:19:47",
            "create_time":"2022-03-11 17:19:43",
            "dirname":"test\/temp\/goods_purchase_donor\/622b141c7a05042448",
            "contract_remark":null,
            "branch_link_man":null,
            "branch_link_tel":null,
            "branch_link_addr":null,
            "branch_link_mail_no":null,
            "hq_link_man":null,
            "hq_link_tel":null,
            "hq_link_addr":null,
            "hq_link_mail_no":null,
            "hq_mail_no_of_code":null,
            "tel":null,
            "linker":null,
            "project_ledger_id":0,
            "goods_list":[
                {
                    "id":894,
                    "goods_id":961,
                    "title":"光缆",
                    "sku":"12芯",
                    "goods_class":"工程材料",
                    "goods_unit":"千米",
                    "remark":"",
                    "brand":"公牛",
                    "qty_finish":"0.00",
                    "qty":"1231.00",
                    "qty_design":"100000.00",
                    "qty_purchase":"3.00",
                    "qty_purchase_finish":"0.00"
                },
                {
                    "id":895,
                    "goods_id":960,
                    "title":"光缆",
                    "sku":"12芯",
                    "goods_class":"工程材料",
                    "goods_unit":"千米",
                    "remark":"",
                    "brand":"电信",
                    "qty_finish":"0.00",
                    "qty":"112.00",
                    "qty_design":"100000.00",
                    "qty_purchase":"2.00",
                    "qty_purchase_finish":"0.00"
                }
            ]
        },
        "help_list":{
            "apm_list":{
                "list":[
                    {
                        "id":197,
                        "name":"甲供领料",
                        "apm_code":"goods_purchase_donor",
                        "desc":"根据项目的甲供材料清单,制甲供领料单,领料之后进行仓库材料入库",
                        "grade":-1,
                        "uid_cc":null,
                        "list":[
                            {
                                "step_id":510,
                                "type":"purchase_donor_file",
                                "result":2,
                                "mode":0,
                                "dmp_id":0,
                                "uid":327,
                                "sort":1,
                                "remark":""
                            }
                        ]
                    }
                ],
                "staff_list":[
                    {
                        "id":806,
                        "uid":658,
                        "name":"1212121",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":110,
                        "dm_name":"项目部",
                        "dmp_name":"副总经理",
                        "tel":"18859596363",
                        "text":"1212121",
                        "label":"项目部>副总经理>1212121",
                        "value":658
                    },
                    {
                        "id":695,
                        "uid":690,
                        "name":"王凯",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":110,
                        "dm_name":"项目部",
                        "dmp_name":"厨师",
                        "tel":"15875469521",
                        "text":"王凯",
                        "label":"项目部>厨师>王凯",
                        "value":690
                    },
                    {
                        "id":865,
                        "uid":691,
                        "name":"采购",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":316,
                        "dm_name":"采购部",
                        "dmp_name":"采购经理",
                        "tel":"12323222222",
                        "text":"采购",
                        "label":"采购部>采购经理>采购",
                        "value":691
                    },
                    {
                        "id":391,
                        "uid":327,
                        "name":"刘瑞卿",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":97,
                        "dm_name":"总经办",
                        "dmp_name":"总经理",
                        "tel":"13333333333",
                        "text":"刘瑞卿",
                        "label":"总经办>总经理>刘瑞卿",
                        "value":327
                    },
                    {
                        "id":378,
                        "uid":298,
                        "name":"张三",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":98,
                        "dm_name":"工程部",
                        "dmp_name":"工程部经理",
                        "tel":"15555555555",
                        "text":"张三",
                        "label":"工程部>工程部经理>张三",
                        "value":298
                    },
                    {
                        "id":368,
                        "uid":317,
                        "name":"李宁",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":98,
                        "dm_name":"工程部",
                        "dmp_name":"工程部经理",
                        "tel":"18888888888",
                        "text":"李宁",
                        "label":"工程部>工程部经理>李宁",
                        "value":317
                    },
                    {
                        "id":369,
                        "uid":318,
                        "name":"王涛",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":98,
                        "dm_name":"工程部",
                        "dmp_name":"工程部副经理",
                        "tel":"17777777777",
                        "text":"王涛",
                        "label":"工程部>工程部副经理>王涛",
                        "value":318
                    },
                    {
                        "id":370,
                        "uid":320,
                        "name":"李恒祥",
                        "branch_id":60,
                        "branch_name":"总部",
                        "dm_id":98,
                        "dm_name":"工程部",
                        "dmp_name":"工程部资料员",
                        "tel":"16666666666",
                        "text":"李恒祥",
                        "label":"工程部>工程部资料员>李恒祥",
                        "value":320
                    }
                ],
                "uid_cc":[
                    null
                ]
            },
            "cor_list":[
                {
                    "id":408,
                    "title":"厦门建设一期测试1",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":327
                },
                {
                    "id":409,
                    "title":"厦门建设一期测试2",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":327
                },
                {
                    "id":410,
                    "title":"厦门建设一期测试3",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":327
                },
                {
                    "id":411,
                    "title":"厦门建设一期测试4",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":327
                },
                {
                    "id":412,
                    "title":"厦门建设一期测试5",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":327
                },
                {
                    "id":415,
                    "title":"厦门建设一期测试6",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":327
                },
                {
                    "id":416,
                    "title":"华信设备技改项目001",
                    "goods_supplier_id":144,
                    "supplier_name":"聚纤缆通信有限公司",
                    "project_manager_id":327
                },
                {
                    "id":421,
                    "title":"厦门GYTS通信光缆",
                    "goods_supplier_id":144,
                    "supplier_name":"聚纤缆通信有限公司",
                    "project_manager_id":327
                },
                {
                    "id":425,
                    "title":"厦门GYTS通信光缆20",
                    "goods_supplier_id":144,
                    "supplier_name":"聚纤缆通信有限公司",
                    "project_manager_id":327
                },
                {
                    "id":429,
                    "title":"11111188",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":null
                },
                {
                    "id":430,
                    "title":"111111888",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":null
                },
                {
                    "id":431,
                    "title":"111111999",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":null
                },
                {
                    "id":432,
                    "title":"222222",
                    "goods_supplier_id":136,
                    "supplier_name":"测试甲方",
                    "project_manager_id":null
                }
            ],
            "storage_list":[
                {
                    "id":33,
                    "dm_id":97,
                    "title":"福州仓库",
                    "manager_id":327,
                    "area":null,
                    "address":"福建福州",
                    "sort":null,
                    "remark":null,
                    "threshold":"0.00",
                    "branch_id":60,
                    "staff_ids":null
                },
                {
                    "id":34,
                    "dm_id":97,
                    "title":"集美区仓库",
                    "manager_id":327,
                    "area":null,
                    "address":"厦门集美区",
                    "sort":null,
                    "remark":null,
                    "threshold":"0.00",
                    "branch_id":60,
                    "staff_ids":null
                },
                {
                    "id":35,
                    "dm_id":97,
                    "title":"广州仓库",
                    "manager_id":327,
                    "area":null,
                    "address":"广东广州",
                    "sort":null,
                    "remark":null,
                    "threshold":"0.00",
                    "branch_id":60,
                    "staff_ids":null
                },
                {
                    "id":36,
                    "dm_id":98,
                    "title":"厦门仓库",
                    "manager_id":317,
                    "area":null,
                    "address":"福建厦门",
                    "sort":null,
                    "remark":null,
                    "threshold":"0.00",
                    "branch_id":60,
                    "staff_ids":[

                    ]
                },
                {
                    "id":37,
                    "dm_id":97,
                    "title":"贵阳项目仓库",
                    "manager_id":327,
                    "area":"2000",
                    "address":"贵阳市",
                    "sort":1,
                    "remark":null,
                    "threshold":"0.00",
                    "branch_id":60,
                    "staff_ids":null
                }
            ],
            "goods_list":[
                {
                    "goods_id":961,
                    "title":"光缆",
                    "brand":"公牛",
                    "sku":"12芯",
                    "goods_class":"工程材料",
                    "goods_unit":"千米",
                    "qty_design":"100000.00",
                    "qty_purchase":"3.00",
                    "qty_purchase_finish":"0.00"
                },
                {
                    "goods_id":960,
                    "title":"光缆",
                    "brand":"电信",
                    "sku":"12芯",
                    "goods_class":"工程材料",
                    "goods_unit":"千米",
                    "qty_design":"100000.00",
                    "qty_purchase":"2.00",
                    "qty_purchase_finish":"0.00"
                },
                {
                    "goods_id":939,
                    "title":"光缆接头盒5",
                    "brand":"亨通",
                    "sku":"96芯",
                    "goods_class":"工程材料",
                    "goods_unit":"个",
                    "qty_design":"100000.00",
                    "qty_purchase":"1.00",
                    "qty_purchase_finish":"0.00"
                }
            ],
            "file_host":"http:xxx",
            "host":"goods_purchase_donor"
        }
    }
}

我们来分析一下,上面data里面的就是返回回来的goods_list,help_list里面的goods_list是总的数据,我们肯定是需要排除掉数据·

// 所以我们来看代码:
let newArr = []
this.data.goods_list.forEach(item => {
	newArr.push(item.goods_id)
})
for (let goods_id of newArr) {
	this.help_list.goods_list = this.help_list.goods_list.filter(item => {
 		return goods_id !== item.goods_id
 	})
}

所以搞定

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2022-03-13 22:09:00  更:2022-03-13 22:10:15 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/18 14:42:31-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码