zoukankan      html  css  js  c++  java
  • javascript库 “linq.js” 的5种使用示例

    今天研究了一下linq.js,很实用。

    下面是写的几个小例子:

    下载源码

    < html > <head > <script type = "text/javascript"src = "linq.min.js" > </script>
    
    <script>
    var peoples = [
        { Name: "张三峰", Sex: "男",City: "北京",Age:23 },
        { Name: "张三峰", Sex: "男",City: "北京",Age:11 },
        { Name: "韩美美", Sex: "女",City: "天津",Age:9 },
        { Name: "李丽丽", Sex: "女",City: "上海",Age:13 },
        { Name: "赵亮亮", Sex: "男",City: "重庆",Age:14 }
      ];
    
        var filteredPeoples = Enumerable.from(peoples).distinct("x=>x.Name").toArray();/ / 根据姓名去重dw(filteredPeoples, "去重");
    
    var orderedPeoples = Enumerable.from(peoples).orderBy("x=>x.Age").toArray(); //正向排序
    dw(orderedPeoples, "正向排序");
    
    var orderedPeoples = Enumerable.from(peoples).orderByDescending("x=>x.Age").toArray(); //倒序
    dw(orderedPeoples, "倒序");
    
    var wherePeoples = Enumerable.from(peoples).where("x=>x.Name=='李丽丽'").toArray(); //Where条件
    dw(orderedPeoples, "Where条件");
    
    var firstPeople = Enumerable.from(peoples).firstOrDefault("x=>x.City=='北京'"); //Where条件
    dw([firstPeople], "firstOrDefault取出首行");
    
    //输入信息到屏幕
    function dw(infos, title) {
        document.write("<b>" + title + "</b><br/>") Enumerable.from(infos).forEach(function(value, index) {
            document.write(value.Name + " - " + value.Sex + " - " + value.City + " - " + value.Age + "<br/>");
        });
        document.write("<br/><br/>")
    } < /script>
    </head > <body >
    
    </body>
    </html > 
  • 相关阅读:
    我是怎么做App token认证的
    APP和服务端-架构设计(二)
    APP和服务端-架构设计(一)
    拦截和跟踪HTTP请求的主要方法及实现
    权限控制方案之——基于URL拦截
    你真的会用Retrofit2吗?Retrofit2完全教程
    科学的解决Http Token拦截器TokenInterceptor实现
    谈谈敏捷开发(转)
    Modbus TCP 示例报文
    Modbus 通信协议详解
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/8795257.html
Copyright © 2011-2022 走看看