linq.jsJavaScript版的LinQ
linq.js 是一个 JavaScript 实现的 LINQ。
主要特性:
- 实现所有 .NET 4.0 的方法
- complete lazy evaluation
- full IntelliSense support for VisualStudio
- two versions - linq.js and jquery.linq.js (jQuery plugin)
- support Windows Script Host
- binding for Reactive Extensions for JavaScript(RxJS) and IntelliSense Generator -> see documentation
- NuGet install support
示例代码:
var jsonArray = [ { "user": { "id": 100, "screen_name": "d_linq" }, "text": "to objects" }, { "user": { "id": 130, "screen_name": "c_bill" }, "text": "g" }, { "user": { "id": 155, "screen_name": "b_mskk" }, "text": "kabushiki kaisha" }, { "user": { "id": 301, "screen_name": "a_xbox" }, "text": "halo reach" } ] // ["b_mskk:kabushiki kaisha", "c_bill:g", "d_linq:to objects"] var queryResult = Enumerable.From(jsonArray) .Where(function (x) { return x.user.id < 200 }) .OrderBy(function (x) { return x.user.screen_name }) .Select(function (x) { return x.user.screen_name + ':' + x.text }) .ToArray(); // shortcut! string lambda selector var queryResult2 = Enumerable.From(jsonArray) .Where("$.user.id < 200") .OrderBy("$.user.screen_name") .Select("$.user.screen_name + ':' + $.text") .ToArray();
评论