最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

LINQ for Javascript (JSON,Arrays, DOM)? - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

A 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().

发布评论

评论列表(0)

  1. 暂无评论