首页 > 代码库 > linqjs试用
linqjs试用
1 var data =http://www.mamicode.com/ { 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 });
linqjs试用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。