zoukankan      html  css  js  c++  java
  • Js Linq

    Linq是对前端集合变量进行操作的一种技术框架,引用文件linq.min.js。
    var myList = [
                { Name: "Victor", Age: 28 },
                { Name: "Jack", Age: 30 },
                { Name: "Simon", Age: 26 },
                { Name: "Hellen", Age: 27 },
                { Name: "Felix", Age: 28 }
        ];
    1.where条件筛选
    var results=myList .where(function(t){return t.Name=="Victor"});
    //返回[{ Name: "Victor", Age: 28 }]
    
    2.select获取指定的属性
    var results=myList .select(function(t){return t.Age});
    //返回[28, 30, 26, 27, 28]
    
    3.orderBy排序
    var results=myList.orderBy(function(t){return t.Age});
    //返回[{ Name: "Simon", Age: 26 }, { Name: "Hellen", Age: 27 },{ Name: "Victor", Age: 28 }, { Name: "Felix", Age: 28 }, { Name: "Jack", Age: 30 }]
    
    4.distinct去重
    var results=myList.distinct(function(a,b){return a.Age==b.Age});
    //[{ Name: "Simon", Age: 26 }, { Name: "Hellen", Age: 27 },{ Name: "Victor", Age: 28 }, { Name: "Jack", Age: 30 }]
    
    5.forEach遍历
    myList.forEach(function(value,index){console.log("Name:"+value.Name+"Age:"+value.Age);})
  • 相关阅读:
    8.22
    webstrom安装流程
    8.21
    8.20
    8.20学习笔记
    使用WebClient异步获取http资源
    导航栏,可直接使用
    asp.net mvc5实现单点登录
    使用C#调用Word的接口生成doc文件与html文件
    下载网页并保存
  • 原文地址:https://www.cnblogs.com/learning-life/p/10718245.html
Copyright © 2011-2022 走看看