• 记录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
    如果您认为这篇文章还不错或者有所收获,您可以通过右边的“打赏”功能 打赏我一杯咖啡【物质支持】,也可以点击右下角的【推荐】按钮【精神支持】,因为这两种支持都是我继续写作,分享的最大动力!
    申明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    RabbitMQ + PHP (二)AMQP拓展安装
    RabbitMQ + PHP (一)入门与安装
    使用 Selenium 实现基于 Web 的自动化测试
    Selenium私房菜系列4 -- Selenium IDE的使用
    解决火狐浏览器安装不上Selenium IDE插件“此附加组件无法安装”
    (技术分享) 解决 Firefox 显示“已阻止载入混合活动内容”的问题
    MyEclipse打开 HTML 报错Failed to create the part's controls
    python2x与python3x的区别
    Python基础总结
    Mycat 读写分离+分库分表
  • 原文地址:https://www.cnblogs.com/meijunzhang/p/8675151.html
Copyright © 2020-2023  润新知