nodejs中使用linq

官网地址 https://github.com/mihaifm/linq

安装 npm install linq

导入 var Enumerable = require(‘linq‘);

例子

1 总览

var myList = [
{ Name: "Jim", Age: 20 },
{ Name: "Kate", Age: 21 },
{ Name: "Lilei", Age: 18 },
{ Name: "John", Age: 14 },
{ Name: "LinTao", Age: 25 }
];
var arrRes = Enumerable.from(myList).orderBy("$.Age").where("$.Age>20").select("x=>x.Age").toArray();
sails.log(arrRes);

2 select

select("x=>x.Age")//数组

select("{a:$.Age,b:$.Name}")//多属性新对象

3 排序

orderBy("$.Age")

orderByDescending()//降序

posted @ 2017-06-29 16:09  simadi  阅读(666)  评论(0编辑  收藏  举报