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": 57022117 },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": 57022133 }34 ]35 36 //linq先按照供应商分组,然后再获取供应商的商品数据37 var supplierGroupArray = Enumerable38 .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": 57022168 }, {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": 57021483 }]84 }] 参考连接:https://stackoverflow.com/questions/26095424/linq-js-group-by-two-properties-fields