两个JsonArray根据一个相同属性合并成一个JsonArray

新手上路,请多包涵

JsonArray 1:

[{
                "purchase_data_id": "1",
                "line_number": "1",
                "warehouse_id": "14",
                "product_id": "1723",
                "sku_id": "28189",
                "barcode": "",
                "expect_qty": "1",
                "actual_qty": "0",
                "purchase_price": "0.1",
                "total_purchase_price": "0.0000",
                "remark": "",
                "updated_at": "0000-00-00 00:00:00",
                "product_img": "http:\/\/easy.ezhangxiu.com\/resource\/img\/common\/default_s.jpg",
                "product_name": "测试",
                "product_code": "ceshi123",
                "unit_name": "件",
                "expect_qty_name": "1件",
                "unit_convert_name": "",
                "big_unit_name": "",
                "unit_convert": "0",
                "sku_code": "1234567",
                "sku_str": "规格: 黑色"
            },
            {
                "purchase_data_id": "2",
                "line_number": "2",
                "warehouse_id": "14",
                "product_id": "1723",
                "sku_id": "28191",
                "barcode": "",
                "expect_qty": "1",
                "actual_qty": "0",
                "purchase_price": "0.1",
                "total_purchase_price": "0.0000",
                "remark": "",
                "updated_at": "0000-00-00 00:00:00",
                "product_img": "http:\/\/easy.ezhangxiu.com\/resource\/img\/common\/default_s.jpg",
                "product_name": "测试",
                "product_code": "ceshi123",
                "unit_name": "件",
                "expect_qty_name": "1件",
                "unit_convert_name": "",
                "big_unit_name": "",
                "unit_convert": "0",
                "sku_code": "12345678",
                "sku_str": "规格: 白色"
            }]

JsonArray2

[{
            "order_sn": "D-20180926-00586",
            "order_product_id": "681",
            "supplier_id": "207",
            "product_id": "1723",
            "sku_id": "28189",
            "quantity": "1",
            "product_name": "测试",
            "cancel_quantity": "0.000",
            "real_quantity": "1",
            "apply_return_quantity": "0",
            "return_quantity": "0",
            "lack_quantity": "0",
            "selling_price": "0.08",
            "price_type": "1",
            "discount_amount": "0",
            "promotion_amount": "0",
            "coupon_amount": "0",
            "sku_info": {
                "sku_id": "28189",
                "sku_name": "规格",
                "sku_text": "黑色",
                "sku_code": "1234567",
                "barcode": "",
                "unit_name": "件",
                "weight": "1.00"
            },
            "is_gift": "0",
            "remarks": "",
            "created_at": "2018-09-26 10:52:52",
            "created_by": "测试",
            "updated_at": "2018-09-26 10:52:52",
            "updated_by": "测试",
            "shipment_quantity": "1",
            "pic": "http:\/\/qiniu.image.ezhangxiu.com\/attach\/69\/207\/201809\/1d\/43\/1dd27977a5a38e8bde0fe5a8c0811043.jpg_160x160xz.jpg"
        },
        {
            "order_sn": "D-20180926-00586",
            "order_product_id": "682",
            "supplier_id": "207",
            "product_id": "1723",
            "sku_id": "28191",
            "quantity": "1",
            "product_name": "测试",
            "cancel_quantity": "0.000",
            "real_quantity": "1",
            "apply_return_quantity": "0",
            "return_quantity": "0",
            "lack_quantity": "0",
            "selling_price": "0.08",
            "price_type": "1",
            "discount_amount": "0",
            "promotion_amount": "0",
            "coupon_amount": "0",
            "sku_info": {
                "sku_id": "28191",
                "sku_name": "规格",
                "sku_text": "白色",
                "sku_code": "12345678",
                "barcode": "",
                "unit_name": "件",
                "weight": "1.00"
            },
            "is_gift": "0",
            "remarks": "",
            "created_at": "2018-09-26 10:52:52",
            "created_by": "测试",
            "updated_at": "2018-09-26 10:52:52",
            "updated_by": "测试",
            "shipment_quantity": "1",
            "pic": "http:\/\/qiniu.image.ezhangxiu.com\/attach\/69\/207\/201809\/1d\/43\/1dd27977a5a38e8bde0fe5a8c0811043.jpg_160x160xz.jpg"
        }]

JsonArray 1 的product_id 和 JsonArray 2 中的order_product_id相等

根据这两个属性合并成一个jsonarray

[{
            "order_sn": "D-20180926-00586",
            "order_product_id": "681",
            "supplier_id": "207",
            "product_id": "1723",
            "sku_id": "28189",
            "quantity": "1",
            "product_name": "测试",
            "cancel_quantity": "0.000",
            "real_quantity": "1",
            "apply_return_quantity": "0",
            "return_quantity": "0",
            "lack_quantity": "0",
            "selling_price": "0.08",
            "price_type": "1",
            "discount_amount": "0",
            "promotion_amount": "0",
            "coupon_amount": "0",
            "sku_info": {
                "sku_id": "28189",
                "sku_name": "规格",
                "sku_text": "黑色",
                "sku_code": "1234567",
                "barcode": "",
                "unit_name": "件",
                "weight": "1.00"
            },
            "is_gift": "0",
            "remarks": "",
            "created_at": "2018-09-26 10:52:52",
            "created_by": "测试",
            "updated_at": "2018-09-26 10:52:52",
            "updated_by": "测试",
            "shipment_quantity": "1",
            "pic": "http:\/\/qiniu.image.ezhangxiu.com\/attach\/69\/207\/201809\/1d\/43\/1dd27977a5a38e8bde0fe5a8c0811043.jpg_160x160xz.jpg"
                "purchase_data_id": "1",
                "line_number": "1",
                "warehouse_id": "14",
                "product_id": "1723",
                "sku_id": "28189",
                "barcode": "",
                "expect_qty": "1",
                "actual_qty": "0",
                "purchase_price": "0.1",
                "total_purchase_price": "0.0000",
                "remark": "",
                "updated_at": "0000-00-00 00:00:00",
                "product_img": "http:\/\/easy.ezhangxiu.com\/resource\/img\/common\/default_s.jpg",
                "product_name": "测试",
                "product_code": "ceshi123",
                "unit_name": "件",
                "expect_qty_name": "1件",
                "unit_convert_name": "",
                "big_unit_name": "",
                "unit_convert": "0",
                "sku_code": "1234567",
                "sku_str": "规格: 黑色"
            },
            {
            "order_sn": "D-20180926-00586",
            "order_product_id": "682",
            "supplier_id": "207",
            "product_id": "1723",
            "sku_id": "28191",
            "quantity": "1",
            "product_name": "测试",
            "cancel_quantity": "0.000",
            "real_quantity": "1",
            "apply_return_quantity": "0",
            "return_quantity": "0",
            "lack_quantity": "0",
            "selling_price": "0.08",
            "price_type": "1",
            "discount_amount": "0",
            "promotion_amount": "0",
            "coupon_amount": "0",
            "sku_info": {
                "sku_id": "28191",
                "sku_name": "规格",
                "sku_text": "白色",
                "sku_code": "12345678",
                "barcode": "",
                "unit_name": "件",
                "weight": "1.00"
            },
            "is_gift": "0",
            "remarks": "",
            "created_at": "2018-09-26 10:52:52",
            "created_by": "测试",
            "updated_at": "2018-09-26 10:52:52",
            "updated_by": "测试",
            "shipment_quantity": "1",
            "pic": "http:\/\/qiniu.image.ezhangxiu.com\/attach\/69\/207\/201809\/1d\/43\/1dd27977a5a38e8bde0fe5a8c0811043.jpg_160x160xz.jpg"
                "purchase_data_id": "2",
                "line_number": "2",
                "warehouse_id": "14",
                "product_id": "1723",
                "sku_id": "28191",
                "barcode": "",
                "expect_qty": "1",
                "actual_qty": "0",
                "purchase_price": "0.1",
                "total_purchase_price": "0.0000",
                "remark": "",
                "updated_at": "0000-00-00 00:00:00",
                "product_img": "http:\/\/easy.ezhangxiu.com\/resource\/img\/common\/default_s.jpg",
                "product_name": "测试",
                "product_code": "ceshi123",
                "unit_name": "件",
                "expect_qty_name": "1件",
                "unit_convert_name": "",
                "big_unit_name": "",
                "unit_convert": "0",
                "sku_code": "12345678",
                "sku_str": "规格: 白色"
            }]
阅读 5.4k
1 个回答

双重for循环,$.extends了解一下
另外,最好是重新生成array,不要改原始数据

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题