admin管理员组文章数量:1415672
i am looking for some input for how to use linq with javascript, there are number of implementations for javascript around.
anybody use any and which is the most patible?
I was looking to be able to use linq against JSON and the DOM
Thanks in advance
i am looking for some input for how to use linq with javascript, there are number of implementations for javascript around.
anybody use any and which is the most patible?
I was looking to be able to use linq against JSON and the DOM
Thanks in advance
Share Improve this question asked Oct 25, 2009 at 9:44 mark smithmark smith 20.9k47 gold badges137 silver badges190 bronze badges2 Answers
Reset to default 4A LINQ-like library for JavaScript is JSLINQ. It seems to have quite a full implementation.
Example from site:
var myList = [
{FirstName:"Chris",LastName:"Pearson"},
{FirstName:"Kate",LastName:"Johnson"},
{FirstName:"Josh",LastName:"Sutherland"},
{FirstName:"John",LastName:"Ronald"},
{FirstName:"Steve",LastName:"Pinkerton"}
];
var exampleArray = JSLINQ(myList)
.Where(function(item){ return item.FirstName == "Chris"; })
.OrderBy(function(item) { return item.FirstName; })
.Select(function(item){ return item.FirstName; });
This should be fine for JSON - as JSON is basically just objects. The DOM, while workable, might be a bit more clunky; you'd probably be best using something else.
JavaScript libraries such as jQuery have methods that work on enumerables and provide filtering, projecting, etc like LINQ does. For example, the jQuery.grep() method works just like LINQ's Where() by filtering items according to the given (anonymous) function and jQuery.map() projects items like LINQ's Select().
本文标签: LINQ for Javascript (JSONarraysDOM)Stack Overflow
版权声明:本文标题:LINQ for Javascript (JSON,Arrays, DOM)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745208009a2647731.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论