zoukankan      html  css  js  c++  java
  • linqjs试用

     1 var data = {
     2     customers: [{
     3         id: 1,
     4         firstname: 'John',
     5         lastname: 'Smith',
     6         sex: 'male'
     7     }, {
     8         id: 2,
     9         firstname: 'Jessica',
    10         lastname: 'Johnson',
    11         sex: 'female'
    12     }, {
    13         id: 3,
    14         firstname: 'Michael',
    15         lastname: 'Williams',
    16         sex: 'male'
    17     }, {
    18         id: 4,
    19         firstname: 'Amber',
    20         lastname: 'Davis',
    21         sex: 'female'
    22     }],
    23     address: [{
    24         id: 1,
    25         address: 'ynkm'
    26     }, {
    27         id: 2,
    28         address: 'ynyx'
    29     }]
    30 };
    31 
    32 var enumerable=Enumerable.from(data.customers);
    33 
    34 enumerable.groupBy("$.firstname.charAt(0)", "x=>x.firstname").forEach(function(group) {
    35     console.log(group.key());
    36     group.forEach(function(aaa) {
    37         console.log(aaa);
    38     });
    39 });
    40 
    41 
    42 enumerable.groupBy("$.firstname.charAt(0)",  "","key,group=>key+'-'+group.select('$.firstname').toJoinedString(',')").forEach(function(group) {
    43     console.log(group);
    44 });
    45 
    46 enumerable.toLookup("$.sex","$.firstname").toEnumerable().forEach(function(group) {
    47     console.log(group.key());
    48     group.orderBy().forEach(function(aaa) {
    49         console.log(aaa);
    50     });
    51 });
    52 
    53 console.log(enumerable.toDictionary("$.firstname").get("Richard"));
    54 console.log(enumerable.toObject("$.firstname")["Richard"]);
    55 
    56 var enumerable2=Enumerable.from(data.address);
    57 //inner join
    58 enumerable.join(enumerable2, "$.id", "$.id", "outer,inner=>{'id':outer.id,'firstname':outer.firstname,'address':inner.address}").forEach(function(aaa) {
    59     console.log(aaa);
    60 });
    61 
    62 enumerable.groupJoin(enumerable2, "$.id", "$.id", "outer,inner=>{'id':outer.id,'firstname':outer.firstname,'address':inner&&inner.address||''}").forEach(function(aaa) {
    63     console.log(aaa);
    64 });
  • 相关阅读:
    java环境变量的搭建,《ecpilse,jdk》的下载
    Android Studio的下载和环境变量的配置
    微信小程序开发者工具包(官方版)
    Activity详解生命周期(Android)
    Android环境变量配置
    Android基础测试题(四)
    Android基础测试题(二)
    手机上实现细线的效果
    前端面试题
    js判断当前浏览器是pc端还是移动端
  • 原文地址:https://www.cnblogs.com/godghdai/p/6917144.html
Copyright © 2011-2022 走看看