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

Jquery.linq 使用示例

时间:2014-06-03 08:13:47      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
 /*Linq JS*/
    //range
    var aa = Enumerable.range(1, 10).toArray();
    var kk = Enumerable.range(1, 10, 3).toArray();
    //select
    kk = Enumerable.range(1, 10).select("value,index=>index + ‘:‘ + value").toArray();
    //where
    kk = Enumerable.range(1, 10).where("y=>y>3").toArray();
    kk = Enumerable.range(1, 10).where("x,y=>y==3").toArray();
    kk = Enumerable.range(1, 10).select("y=>y>3").toArray();

    //from
    var arry = [1, 2, 3, 3, 5, 6, 7, 8, 9, 10];
    kk = Enumerable.from(arry).where("x=>x>3").toArray();
    kk = Enumerable.from(arry).where("$>3").toArray();

    var arryObject = [{ Dept: "MFG", EMP: "425305" },
                      { Dept: "MFG", EMP: "425306" },
                      { Dept: "MFG", EMP: "425307" },
                      { Dept: "FINC", EMP: "425308" },
                      { Dept: "INFO", EMP: "425309" },
                      { Dept: "INFO", EMP: "425311" },
                      { Dept: "INFO", EMP: "425312" },
                      { Dept: "FINC", EMP: "425313" },
                      { Dept: "FINC", EMP: "425314" },
                      { Dept: "FINC", EMP: "425315"}];

    kk = Enumerable.from(arryObject).where("$.Dept==‘MFG‘").select("$.Dept").toArray();
    kk = Enumerable.from(arryObject).where("val,index=>val.Dept==‘MFG‘").select("val=>val.Dept").toArray();
    kk = Enumerable.from(arryObject)
                   .where(function (val, index) { return val.Dept == ‘MFG‘ && val.EMP == ‘425305‘ })
                   .toArray();
    //forEach
    var ss = [];
    Enumerable.from(arryObject).forEach(function (val, index) {
        ss.push(val);
    });

    //distinct
    var qq = Enumerable.from(arryObject)
                       .distinct("x=>x.Dept")
                       .select("x=>x.Dept")
                       .toArray();
    //groupBy
    var newArray = [];
    var oGrop = Enumerable.from(arryObject).groupBy("$.Dept").forEach(function (val) {
        var ee = Enumerable.from(val).toArray();
        var strDept = ee[0].Dept;
        var iLength = ee.length;
        var obj = { Dept: strDept, Length: iLength };
        newArray.push(obj);
    });

    var oGrop = Enumerable.from(arryObject).groupBy("$.Dept").select(function (val) {
        var ee = Enumerable.from(val).toArray();
        var strDept = ee[0].Dept;
        var iLength = ee.length;
        return { Dept: strDept, Length: iLength };
    }).toArray();
bubuko.com,布布扣

 

Jquery.linq 使用示例,布布扣,bubuko.com

Jquery.linq 使用示例

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/gossip/p/3760791.html

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