码迷,mamicode.com
首页 > Web开发 > 详细

在.NET下学习Extjs(第三个案例 Array的过滤方法(filter))

时间:2015-02-10 21:42:31      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

Ext.Array.filter(Array array,Function fn,Object scope):Array

array是一个数组,fn是过滤函数,scope是作用域,filter返回的是一个新的数组.

遍历原数组的每一项,经过滤函数过滤,为true的留下构建成新的数组.

构建代码如下:

 

技术分享
 1 <!DOCTYPE html>
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 5     <title></title>
 6     <link href="resources/css/ext-all.css" rel="stylesheet" />
 7     <script src="bootstrap.js"></script>
 8     <script src="ext-all.js"></script>
 9     <script>
10         Ext.onReady(function () {
11             var oldArray = [6,5,4,3,2,1,0,9,8];//原来的数组
12             var newArray = Ext.Array.filter(oldArray, function (item) {
13                 //过滤,数组中大于4的元素留下构建新的数组
14                 if (item > 4) {
15                     return true;
16                 } else {
17                     return false;
18                 }
19             }, this);//this表示作用域
20             Ext.MessageBox.alert("Result", newArray.join("-"), function () {
21                 alert("完事");
22             });//弹窗显示结果
23         })
24     </script>
25 </head>
26 <body>
27 
28 </body>
29 </html>
View Code

 

右键->在浏览器查看

 

点击OK按钮结束.第三个案例结束了,是不是很简单.

在.NET下学习Extjs(第三个案例 Array的过滤方法(filter))

标签:

原文地址:http://www.cnblogs.com/taotang/p/4284914.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!