数据过滤器示例

导读:
Posted in February 15th, 2008
在雅虎的FLEX社区求助一个关于数据过滤的问题,因为在不久的将来将要做类似的工作,所以我将此视为与挑战,也认为这是一个绝佳的练习机会
我们很多人使用FLEX是因为它客户端强大的数据过滤功能,在数据过滤方面 也做过一些研究,在我的心目中更加复杂的数据过滤功能永远是一项具有挑战性的工作
也许我在这个领域只是没有经验,但是我经常在决定重要性顺序的时候犯难,例如 我有一个数据表格,该数据表格有三例分别显示:雇员姓名,所在区域,所在类别。我希望能够搜索这些区域的任意域,因此我开始向文本框输入一些数据并且在他能够恰当的过滤些数据,假定文本过滤器位于输入域之外,并且我还有一些复选框我希望以此来过滤一些区域,我有一些复选列表和希望以此来过滤一些目录。我的全部示例工作就包括这些内容,点击上面的超链接右击查看源代码你就可以看见一个更好的解决方案。这场景中的一个问题就是:
// CODE
//
Filterfunction
public function processFilter(item:Object):Boolean
... {
varresult:Boolean=false;
getRegions();
//returns“1,2,3“
getCategories();//returns“2,3,4“

trace(’item.regionID:‘
+item.regionID);
trace(’item.catID:‘
+item.catID);

if(regArray.length)
...{
for(vari:StringinregArray)
...{
trace(’regArray[i]:‘
+regArray[i]);//Ifnofiltertext,oramatch,thentrue
if(item.regionID.toString()==regArray[i].toString())
result
=true;
}

}


if(catArray.length)
...{
for(vark:StringincatArray)
...{
trace(’catArray[k]:‘
+catArray[k]);
//Ifnofiltertext,oramatch,thentrue
if(item.catID.toString()==catArray[k].toString())...{
result
=true;
}

}


returnresult;
}
首先我去掉所有区域的复选,这样列表就空了,但是我想选择列表中所有的程序员,因此我在下拉列表框中选择程序员然后单击处理按钮,这样我就获得所有的程序员,如果说我只想获得AUSTIN这个区的所有程序员,但是在这列表中获得的程序员以及AUSTIN的所有清单。这样做我所需要的主要过滤器需要一些公开的协助,这是我正是我所求助的
但是我还是不清楚我还需要做哪些工作,当然这已经是一个很好的开端这是我还需要做很多工作。另外我还在考虑不同的IF 声明和开关逻辑
英文原文:
Some one online mailed the flexcoders yahoo list and asked for some assistance… I took this as a challenge, because I have been assigned at work to do some similar tasks within the near future, and I thought this was a perfect opportunity to get some practice in.
Many of us want to use flex because of it’s great filtering data (on the client) capabilities. I’ve been doing some research on filtering data, and more complex filtering capabilities, and filtering data has always been a challenge in my mind.Maybe I am just far too inexperienced in this area, but I always have trouble deciding what the order of importance is, for example.I have a form with a datagrid, and this datagrid shows 3 columns.
-Employee Name
-Region (that they are located in)
-Category (of employee that they are)
I want to be able to search any of these fields, so I start typing in some text box expecting my datagrid to filter properly… Lets say the text box filters out the name field… and I have a series of check boxes that I want to filter the Regions off, and I have a multiple select List that I would like to filter my categories off… I have all of this working as of right now by referring to the link above, and right clicking to view the source, you’ll be able to get a better idea. One of the issues that I am having in this scenario is:
I uncheck all of my Regions, and the list goes blank… thats fine, but say I want to view all of the Programmers in the list, so I select “Programmer” and then click my Process Filter button, then that lets me view all of my programmers… say i want to only view all of the programmers in Austin So I check Austin, but in the list I get:All of the Employees that are in the “Programmer” category, as well as ALLL of the Employees that are in Austin… the main filter that I have doing this needs some public assistance, that I’m turning to the groups for.
// CODE
//
Filterfunction
public function processFilter(item:Object):Boolean
... {
varresult:Boolean=false;
getRegions();
//returns“1,2,3“
getCategories();//returns“2,3,4“

trace(’item.regionID:‘
+item.regionID);
trace(’item.catID:‘
+item.catID);

if(regArray.length)
...{
for(vari:StringinregArray)
...{
trace(’regArray[i]:‘
+regArray[i]);//Ifnofiltertext,oramatch,thentrue
if(item.regionID.toString()==regArray[i].toString())
result
=true;
}

}


if(catArray.length)
...{
for(vark:StringincatArray)
...{
trace(’catArray[k]:‘
+catArray[k]);
//Ifnofiltertext,oramatch,thentrue
if(item.catID.toString()==catArray[k].toString())...{
result
=true;
}

}


returnresult;
}
that verifies that the data being passed is equal to the data that you want to see… I need an “or” statement in here to resemble the following
if (item.catID.toString() == catArray[k].toString() ||
item.catID.toString()
== regArray[i].toString())
... {
result
=true;
}
there is the main line of filter work
I just can’t quite get my mind wrapped around what I need to do, But this is a great start on the issue… I just need to do. I think i’m going to need a few different if statements:
one that decides if both the categories and regions are being used to filter, then have the main filter line do somethingone that states if the catArray.length is false, then do something with that main filter lineone that does the same for the regArray.length as well…that might do the trick or at least get it started, but anyone out there that has came across this and cares to help a fellow programmer out… It would be very much appreciated!
Thanks a lot for taking the time to read this.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值