weixin_45988163
2021-09-17 09:43
采纳率: 0%
浏览 44

json同样的id 怎么合并数据


"DataSource": {
        "Rows": [{
            "Idpartner": "1",
            "partnerName": "002",
            "voucherDate": "",
            "noSettlepartnerName": "",
            "departmentName": "",
            "personName": "",
            "memo": "",
            "voucherTypeName": "期初余额",
            "voucherCode": "",
            "origAmount": "",
            "origSettleAmount": "",
            "origBalanceAmount": "",
            "GroupLevel": "0",
            "rowType": "D",
            "reportRowType": "0"
        }, {
            "Idpartner": "1",
            "partnerName": "002",
            "voucherDate": "2021-09-14",
            "noSettlepartnerName": "002",
            "departmentName": "",
            "personName": "",
            "memo": "",
            "voucherTypeName": "销货单",
            "voucherCode": "SA-2021-09-0001",
            "origAmount": "1130.00",
            "origSettleAmount": "",
            "origBalanceAmount": "1130.00",
            "GroupLevel": "0",
            "rowType": "D",
            "reportRowType": "10"
        }, {
            "Idpartner": "1",
            "partnerName": "002",
            "voucherDate": "2021-09-14",
            "noSettlepartnerName": "002",
            "departmentName": "",
            "personName": "",
            "memo": "",
            "voucherTypeName": "收款单",
            "voucherCode": "SK-2021-09-0005",
            "origAmount": "",
            "origSettleAmount": "20000.00",
            "origBalanceAmount": "-18870.00",
            "GroupLevel": "0",
            "rowType": "D",
            "reportRowType": "10"
        }, {
            "Idpartner": "1",
            "partnerName": "002",
            "voucherDate": "2021-09-14",
            "noSettlepartnerName": "002",
            "departmentName": "",
            "personName": "",
            "memo": "",
            "voucherTypeName": "销货单",
            "voucherCode": "SA-2021-09-0002",
            "origAmount": "440000.00",
            "origSettleAmount": "",
            "origBalanceAmount": "421130.00",
            "GroupLevel": "0",
            "rowType": "D",
            "reportRowType": "10"
        }, {
            "Idpartner": "2",
            "partnerName": "测试部门",
            "voucherDate": "",
            "noSettlepartnerName": "",
            "departmentName": "",
            "personName": "",
            "memo": "",
            "voucherTypeName": "期初余额",
            "voucherCode": "",
            "origAmount": "",
            "origSettleAmount": "",
            "origBalanceAmount": "",
            "GroupLevel": "0",
            "rowType": "D",
            "reportRowType": "0"
        }, {
            "Idpartner": "2",
            "partnerName": "测试部门",
            "voucherDate": "2021-09-07",
            "noSettlepartnerName": "测试部门",
            "departmentName": "测试库",
            "personName": "张三",
            "memo": "",
            "voucherTypeName": "收款单",
            "voucherCode": "SK-2021-09-0004",
            "origAmount": "",
            "origSettleAmount": "9388.00",
            "origBalanceAmount": "-9388.00",
            "GroupLevel": "0",
            "rowType": "D",
            "reportRowType": "10"
        }]
    },
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • weixin_45988163 2021-09-17 09:44

    我怎么根据 id一样的 合并数据

    评论
    解决 无用
    打赏 举报
  • 孙叫兽 2021-09-17 09:46

    参考

    
    ```javascript
    注意:arr1 是基础 把arr2合并到arr1中 ,汇成一个总的arrs  这个arr1中的id 和  arr2中的periodId  是一一对应的。
    let arr1 = [
     {id:64,period:"10:00"},
     {id:65,period:"12:00"},
     {id:66,period:"14:00"},
     {id:67,period:"18:00"},
    ]
    let arr2 = [
        {   
            period:'10:00',
            periodId: 64,
            products:[
            {
                goodName: "套餐测试A-001",
                goodSn: "1368017317954457600",
                id: 252,
                limitedNum: 1,
                productId: 1658,
                remark: null,
                seckillPeriodId: 64,
                seckillPrice: 1,
                seckillStock: 1,
                skuId: 2947,
                status: 4,
                stock: 97,
                unitPrice: 100,
           }
          ]
      }
    ]
     const arrs = arr1.map(item => {
        const data = arr2.find(i => item.id == i.periodId)
        return {
          ...item,
          ...data,
          products: data ? data.products : []
        }
      })
    console.log(arrs)
    
    

    ```

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题