什么是领先的 LINQ for JavaScript 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2478038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the leading LINQ for JavaScript library?
提问by Tom Tresansky
I'm looking for a JavaScript library that will allow me to query complex JSON objects using a LINQ-like syntax. A quick search found a couple of promising options that look they might offer what I need:
我正在寻找一个 JavaScript 库,它允许我使用类似 LINQ 的语法查询复杂的 JSON 对象。快速搜索发现了几个有希望的选项,看起来它们可能提供我需要的东西:
- Does any one have any experience using them?
- What are some pros and cons?
- Is the performance comparable?
- Does the function-passing syntax of LINQ to JavaScript offer any hidden benefits (I personally find the syntax of jLinq more appealing on first glance)?
- What have you found lacking in either project?
- Did you ever try contacting the authors? How responsive were they?
- What project is more widely used?
- 有没有人有使用它们的经验?
- 有什么优点和缺点?
- 性能有可比性吗?
- LINQ to JavaScript 的函数传递语法是否提供了任何隐藏的好处(我个人觉得 jLinq 的语法乍一看更有吸引力)?
- 您发现这两个项目中缺少什么?
- 你有没有尝试联系作者?他们的反应如何?
- 什么项目应用比较广泛?
I think it will be the first one to get a thorough try-out.
我认为这将是第一个进行彻底试用的人。
采纳答案by Richard Anthony Hein
Have you seen Rx for Javascript, yet? That's what you want.
你见过Rx for Javascript吗?那就是你想要的。
回答by Nathan Palmer
You might want to check out linq.js. It follows the .NET lambda syntax and looks to be well integrated in a Microsoft environment.
您可能想查看linq.js。它遵循 .NET lambda 语法,看起来可以很好地集成到 Microsoft 环境中。
LINQ for JavaScript - http://linqjs.codeplex.com/
用于 JavaScript 的 LINQ - http://linqjs.codeplex.com/
Pros
优点
- Implements all .NET 4.0 methods
- Complete lazy evaluation
- Full IntelliSense support for VisualStudio
- Supports jQuery
- Supports Windows Script Host
- Binding for Reactive Extensions for JavaScript(RxJS) and IntelliSense Generator
- NuGet install support
- Updated recently (last release Jan 2011)
- Syntax conforms to lambda syntax in C#
- 实现所有 .NET 4.0 方法
- 完成懒惰评估
- 对 VisualStudio 的完整 IntelliSense 支持
- 支持jQuery
- 支持 Windows 脚本宿主
- 绑定 JavaScript(RxJS) 和 IntelliSense Generator 的响应式扩展
- NuGet 安装支持
- 最近更新(上次发布于 2011 年 1 月)
- 语法符合 C# 中的 lambda 语法
Cons
缺点
- The linq.js library is a little large.
- If you are already using jQuery or other js library, the most commonly used functionality is probably already available. See especially jQuery's filter, and 'Any' methods.
- linq.js 库有点大。
- 如果您已经在使用 jQuery 或其他 js 库,那么最常用的功能可能已经可用。请特别查看 jQuery 的filter和 'Any' 方法。
回答by Daniel Earwicker
The most basic and frequently used Linq operators are very commonly defined in widely used JS libraries. They just have different names (in fact, they have more traditional names than in Linq). Selectbecomes map, Wherebecomes filter, Firstand FirstOrDefaultbecome [0].
最基本和最常用的 Linq 运算符在广泛使用的 JS 库中非常常见。它们只是名称不同(实际上,它们的名称比 Linq 中的更传统)。Select变map,Where变filter,First而FirstOrDefault变[0]。
Almost no library I know of (including I think the ones you linked to) bother to make the implementation lazy as in .NET Linq, they just evaluate immediately using arrays.
我所知道的库(包括我认为您链接到的库)几乎没有像在 .NET Linq 中那样懒惰地使实现变得懒惰,它们只是使用数组立即评估。
For a very nice, complete set of functional list operations, try: http://osteele.com/sources/javascript/functional/
对于一套非常好的、完整的功能列表操作,请尝试:http: //osteele.com/sources/javascript/functional/
回答by Matthew Nichols
I recommend taking a look at underscore.js. It is not a direct LINQ port like some of the others, but is a very comfortable "LINQ-like" experience. It supports all the filter, sort and project options that I need and has excellent documentation and community support.
我建议看看underscore.js。它不像其他一些直接 LINQ 端口,而是一种非常舒适的“类似 LINQ”的体验。它支持我需要的所有过滤器、排序和项目选项,并具有出色的文档和社区支持。
As a bonus for Knockoutusers, there is UnderscoreKOthat adds Underscore's array methods to Knockout's observable arrays. Demo
至于奖金淘汰赛的用户,有UnderscoreKO,增加了下划线的阵列方法淘汰赛的观察到的阵列。演示
回答by Kristian Abrahamsen
I personally find the LINQ/set operations Union, Intersect, Except and Distinct on enumerables in .NET. very useful. There is a jquery plugin called jQuery Array Utilitieswhich provides these methods to be used on arrays.
我个人发现 .NET 中可枚举的 LINQ/set 操作 Union、Intersect、Except 和 Distinct。很有用。有一个名为jQuery Array Utilities的 jquery 插件,它提供了用于数组的这些方法。
Code examples:
代码示例:
$.distinct([1, 2, 2, 3])
returns [1,2,3]
返回 [1,2,3]
$.union([1, 2, 2, 3], [2, 3, 4, 5, 5])
returns [1,2,3,4,5]
返回 [1,2,3,4,5]
$.instersect([1, 2, 2, 3], [2, 3, 4, 5, 5])
returns [2,3]
返回 [2,3]
$.except([1, 2, 2, 3], [3, 4, 5, 5])
returns [1, 2]
返回 [1, 2]
回答by Janus Troelsen
$linq: http://jscriptlinq.codeplex.com/
$linq:http: //jscriptlinq.codeplex.com/
var users = [{username: "asmith", domain: "north_america"},
{username: "tmcfarland", domain: "europe"},
{username: "cdeckard", domain: "nort_america"}];
var groups = [{user: "ASMITH", groupName: "base_users"},
{user: "TMCFARLAND", groupName: "admins"},
{user: "CDECKARD", groupName: "base_users"},
{user: "CDECKARD", groupName: "testers"}];
var results = $linq(users).join(groups,
function (x) { return x.username; }, // key for 'users'
"x => x.user", // key for 'groups'
function (outer, inner) // function to generate results
{
return "user: " + outer.username +
", domain: " + outer.domain +
", group: " + inner.groupName;
},
"(x, y) => x.toLowerCase() == y.toLowerCase()"); // compare keys case-insensitively
回答by orad
There are some duplicating libraries out there that try to port LINQ to JavaScript with a similar syntax and method names. However, in the JS community, the library that is getting really popular and providing the same functionality is Underscore.js.
有一些重复的库尝试使用类似的语法和方法名称将 LINQ 移植到 JavaScript。但是,在 JS 社区中,真正流行并提供相同功能的库是Underscore.js。
回答by user302084
I've tried out most of these -- and I really like $linq: http://jscriptlinq.codeplex.com/the best. It simply works the way you would expect c# linq to work -- including the chain ability.
我已经尝试了其中的大部分——我真的很喜欢 $linq:http: //jscriptlinq.codeplex.com/最好的。它只是按照您期望 c# linq 的工作方式工作——包括链能力。
回答by Jacob Thomason
I'm looking for something like this myself and came across...
我自己正在寻找这样的东西并遇到了......
http://www.hugoware.net/Projects/jLinq
http://www.hugoware.net/Projects/jLinq
This looks really great! Maybe I just don't understand the point of Rx and observables compared to setting event handlers through something like jQuery.
这看起来真的很棒!与通过 jQuery 之类的东西设置事件处理程序相比,也许我只是不明白 Rx 和 observables 的意义。
回答by suckgamony
I recently made a LINQ library for JavaScript. It implemented most LINQ functions provided by .NET and it is the fastest of all the LINQ libraries.
我最近为 JavaScript 制作了一个 LINQ 库。它实现了 .NET 提供的大多数 LINQ 函数,并且它是所有 LINQ 库中速度最快的。

