zoukankan      html  css  js  c++  java
  • 记录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
    如果您认为这篇文章还不错或者有所收获,您可以通过右边的“打赏”功能 打赏我一杯咖啡【物质支持】,也可以点击右下角的【推荐】按钮【精神支持】,因为这两种支持都是我继续写作,分享的最大动力!
    申明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    js窗口拖动 模版
    js中准确判断数据类型的方法
    ArcGis Python脚本——批量对影像、要素类定义投影
    ArcGis 属性表.dbf文件使用Excel打开中文乱码的解决方法
    解析ArcGis拓扑——根据拓扑错误记录提取shp文件、导出Excel表格
    解析ArcGis拓扑——检查的流程,以面重叠检查为例
    ArcGis Classic COM Add-Ins插件开发的一般流程 C#
    解析ArcGis的标注(三)——标注的放置 与 转注记修改
    解析ArcGis的标注(二)——认识ArcGis标注标签
    解析ArcGis的标注(一)——先看看分数式、假分数式标注是怎样实现的
  • 原文地址:https://www.cnblogs.com/meijunzhang/p/8675151.html
Copyright © 2011-2022 走看看