码迷,mamicode.com
首页 > Web开发 > 详细

linqjs试用

时间:2017-05-29 09:52:00      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:customers   pre   inner   data   toe   key   last   aaa   ons   

 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 });

 

linqjs试用

标签:customers   pre   inner   data   toe   key   last   aaa   ons   

原文地址:http://www.cnblogs.com/godghdai/p/6917144.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!