拼吾爱程序人生

首页 » 其他编程 » javascript » LINQ to JavaScript
cobra - 2008-4-26 11:41:00
文/www.codeplex.com/JSLINQ  译/worksguo  出处/博客园

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>

 您可能对 [javascript] 的这些文章也感兴趣:

连续滚动的制作
让弹出窗口变得“体贴”一些
用javascrpt实现淘宝首页的间隔性滚动效果
JavaScript极速狂飙:组合拼接字符串的效率
如何制作浮动广告
简易而又灵活的Javascript拖拽框架(三)
用javascript 转换外部链接样式
用JavaScript实现变色背景和文字
javascript应用:实现复选框全选/全不选切换
Javascript面向对象编程
cobra - 2008-4-26 11:43:00
二:体验
--------------------------------------------------------------------------------


(1)首先写一个数组:

Code


(2)添加查询。

Code


结果是:
Chris

其实上面有的那些操作符的使用,你在下载官方的文件时里面就有很多事例,就能让能掌握拉.


--------------------------------------------------------------------------------
我就把筛选数据序列化为JSON穿回服务端.(我一直想做纯JS的网站!)


接着你再添加两个方法:

Code


服务端:

Code


页面

Code


其实比较简单,但我想要用LINQ to JavaScript,要这样才完整嘛.
1
查看完整版本: LINQ to JavaScript
Modify by pin5i DZNT_ExpandPackage 2.1.3237 2007-2008 pin5i.com
  Total Unique Visitors: