记录linq.js神器之gorup by 多个字段的方法

 1 //数据源
 2 var dataSource = [{
 3 "imgUrl": "https://xxxxx/babel/jfs/t10471/26/2498586860/80931/cb688812/59f7eb8aN5fa580e0.jpg",
 4 "resourceBaseType": 3,
 5 "resourceBaseCode": "5747502",
 6 "purchasingQuantity": 1,
 7 "resourceBaseName": "阳光照明led球泡灯泡2.8W节能灯E27螺口黄光3000K(十只装)",
 8 "unitPrice": 59,
 9 "isAddedInvoice": true,
10  "isAccountPeriod": true,
11  "is7ToReturn": true,
12  "belongUserId": 281,
13  "belongMemberId": 101,
14  "supplierName": "",
15  "errorMsg": "",
16  "id": 570221
17  },
18  {
19  "imgUrl": "https://xxxx/babel/jfs/t10471/26/2498586860/80931/cb688812/59f7eb8aN5fa580e0.jpg",
20  "resourceBaseType": 3,
21  "resourceBaseCode": "5747502",
22  "purchasingQuantity": 1,
23  "resourceBaseName": "阳光照明led球泡灯泡2.8W节能灯E27螺口黄光3000K(十只装)",
24  "unitPrice": 59,
25  "isAddedInvoice": true,
26  "isAccountPeriod": true,
27  "is7ToReturn": true,
28  "belongUserId": 281,
29  "belongMemberId": 101,
30  "supplierName": "",
31  "errorMsg": "",
32  "id": 570221
33  }
34  ]
35 
36  //linq先按照供应商分组,然后再获取供应商的商品数据
37  var supplierGroupArray = Enumerable
38 .from(checkedResources)
39 .groupBy(
40  "{UserId:$.belongUserId,MemberId:$.belongMemberId,Name:$.supplierName}",
41  null,
42  "{belongUserId:$.UserId,belongMemberId:$.MemberId,supplierName:$.Name,resourceLists: $$.toArray()}",
43  "$.UserId + $.MemberId + $.Name")
44 .toArray();
45 
46 
47 //group by 之后的结果集
48 
49 [{
50     "belongUserId": 281,
51     "belongMemberId": 101,
52     "supplierName": "",
53     "resourceLists": [{
54         "imgUrl": "https://xxxxxx/babel/jfs/t10471/26/2498586860/80931/cb688812/59f7eb8aN5fa580e0.jpg",
55         "resourceBaseType": 3,
56         "resourceBaseCode": "5747502",
57         "purchasingQuantity": "1",
58         "resourceBaseName": "阳光照明led球泡灯泡2.8W节能灯E27螺口黄光3000K(十只装)",
59         "unitPrice": 59,
60         "isAddedInvoice": true,
61         "isAccountPeriod": true,
62         "is7ToReturn": true,
63         "belongUserId": 281,
64         "belongMemberId": 101,
65         "supplierName": "",
66         "errorMsg": "",
67         "id": 570221
68     }, {
69         "imgUrl": "https://xxxx/babel/jfs/t16339/157/1451930239/33640/8e3a8afc/5a5476b1N7d93b255.jpg",
70         "resourceBaseType": 3,
71         "resourceBaseCode": "5617370",
72         "purchasingQuantity": "1",
73         "resourceBaseName": "美的(Midea) LED灯泡 蜡烛尖泡 3W E14小螺口 3000K 暖白色  单只装 金色",
74         "unitPrice": 14.9,
75         "isAddedInvoice": true,
76         "isAccountPeriod": true,
77         "is7ToReturn": true,
78         "belongUserId": 281,
79         "belongMemberId": 101,
80         "supplierName": "",
81         "errorMsg": "",
82         "id": 570214
83     }]
84 }]

参考连接:https://stackoverflow.com/questions/26095424/linq-js-group-by-two-properties-fields

 

转载于:https://www.cnblogs.com/meijunzhang/p/8675151.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值