博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
记录linq.js神器之gorup by 多个字段的方法
阅读量:4692 次
发布时间:2019-06-09

本文共 2741 字,大约阅读时间需要 9 分钟。

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

 

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

你可能感兴趣的文章
农银电商项目学习笔记(一)
查看>>
MockObject
查看>>
Chukwa
查看>>
(转)Maven仓库——私服介绍
查看>>
设计模式之工厂模式
查看>>
仿复制粘贴功能,长按弹出tips的实现
查看>>
Kubernetes-Host网络模式应用
查看>>
第三次作业
查看>>
使用HTML5构建iOS原生APP(2)
查看>>
sqlplus terminators - Semicolumn (;), slash (/) and a blank line
查看>>
省选知识清单/计划列表(咕?)
查看>>
远程桌面(3389)复制(拖动)文件
查看>>
转 lucene3搜索引擎,索引建立搜索排序分页高亮显示, IKAnalyzer分词
查看>>
bootstrap datetimepicker 位置错误
查看>>
9结构型模式之代理模式
查看>>
第二节 整型数据
查看>>
Python 序列
查看>>
Liferay的架构:缓存(第一部分)
查看>>
初识B/S结构编程技术
查看>>
方法、hadoop源码之JobQueueTaskScheduler-by小雨
查看>>