LINQ to JavaScript是使用JavaScript来做出类似LINQ样的功能,可以做到在客户端对一些数据筛选,加强了对数组的操作.其中有一些功能本来JavaScript就有如对数组数据过滤的功能,再想想就这样筛选数据没有什么大的意义,但要把筛选后的数据又通过JSON反回到服务端那就有用拉.这样可以和Silverlight1.0,asp.net ajax在一起使用,它能对他们起到一定的辅助作用吧.(还有这个只能对数组中使用)
资料:
http://www.nikhilk.net/ScriptAndLINQ.aspx
http://pietschsoft.com/post/2008/01/LINQ-to-JavaScript-(JSLINQ)-Open-Source-Project-Launched!.aspx
http://www.codeplex.com/JSLINQ
一:介绍
LINQ to JavaScript(JSLINQ)是一个LINQ to Object在 javaScript中的实现,它对JavaScript Arrary Objcet构建一些列的扩展方法.如果你使用一个Array,你能使用LINQ to JavaScript.
现在的发布版本是是1.03支持
Operators
- From
- Where
- OrderBy
- Select
Added the OrderByDescending Operator
- Added the SelectMany Operator
- Added the Count Operator
- Added the Distinct Operator
- Added the Any Operator
- Added the All Operator
- Made it so you can access the elements "index" within the clause/predicate of each of the following Operators: Where, Count, Any, All
- Added the Reverse Operator, this also allows access to the elements "index" within the clause/predicate
- Added First Operator, this also allows access to the elements "index" within the clause/predicate
- Added Last Operator, this also allows access to the elements "index" within the clause/predicate
- Added ElementAt Operator
- Added Concat Operator - this is identical to JavaScripts Array.concat method
Intersect Operator
- Added DefaultIfEmpty Operator
- Added ElementAtOrDefault Operator
- Added FirstOrDefault Operator
- Added LastOrDefault Operator
- Unit Test Created
--- Intial testing of the Samples Unit Tests yielded the following speed results for all tests:
------ IE7: ~10 milliseconds
------ FireFox 2: ~10 milliseconds
------ Safari 3 for Windows: ~4 milliseconds
使用
(1)在你的工程中添加JSLINQ.js文件;
(2)在你的页面中添上代码<script type="text/javascript" src="JS/JSLINQ.js"></script>
二:体验
(1)首先写一个数组:
(2)添加查询。
结果是:
Chris
其实上面有的那些操作符的使用,你在下载官方的文件时里面就有很多事例,就能让能掌握拉.
我就把筛选数据序列化为JSON穿回服务端.(我一直想做纯JS的网站!)
接着你再添加两个方法:
服务端:
页面
其实比较简单,但我想要用LINQ to JavaScript,要这样才完整嘛.
worksguo
欢迎评论