Client-side data filtering with E4X and XMLListCollection
来源:互联网 发布:淘宝上的小米手环2 编辑:程序博客网 时间:2024/05/22 07:41
Suppose you're browsing a online catalog of mobile phones. You wantto see only those handsets that are of a particular brand and fallwithin a specific price range.
In other words, name == $name && price >= $minPrice && price <= $maxPrice
This was easy to build in traditional web applications, where thefiltering happened on the server side. The advantage of RIAs, though,is that a lot of such operations can be done purely on the client side,thus avoiding unnecessary server trips.
Last year I wrote a class called FilteredDataProviderwhose purpose was to filter a data set on a given field. I seem to havemisplaced the source for it, but never mind, it's no longer required inFlex 2.0. Data filtering is now trivial with ActionScript 3's new E4Xsupport combined with Flex's XMLListCollection.
To use this feature on data returned from an HTTPService
, first set the service object's resultFormat
to e4x
.
<mx:HTTPService id="catalogService"url="data/catalog.xml"
resultFormat="e4x" />
Next, create an XMLListCollection
bound to the service. Also specify a filterFunction
for the collection.
<mx:XMLListCollection id="xlc"
source="{catalogService.lastResult.*}"
filterFunction="filterProduct" />
<mx:Script>
<![CDATA[
private function filterProduct(item:Object):Boolean
{
return item.name.match(new RegExp("^" + brandText.text, "i"))
&& item.price >= priceSlider.values[0]
&& item.price <= priceSlider.values[1];
}
]]>
</mx:Script>
The filterProduct
function above is called for every item in the xlc
collection. It returns true
if the item passes its test; otherwise the item is filtered out.
Finally, here's an example of a DataGrid
binding to the collection.
<mx:DataGrid dataProvider="{xlc}" />
- Client-side data filtering with E4X and XMLListCollection
- Using jQuery with Client-Side Data Binding
- E4X: Predicate Filtering with Regular Expressions
- client-side and server-side
- Filtering Data with PHP
- Uploading File with PHP and Client Side Scripting
- Jax-ws server side and client side
- Working with Client-Side Script(MSDN)
- Detect missing images with client-side script
- Telerik Grid Server Side Paging, Sorting and Filtering
- AJAX and scripting Web services with E4X, Part 1
- AJAX and scripting Web services with E4X, Part 2
- Expand and Collapse Rows on Client-Side
- About client-side form validation and frameworks
- Riak, haproxy, and client side applications
- Client and Server side Dynamic Pages
- Accessing Server-Side Data with Flex
- Use IE userdata behavior as a client-side data storage
- GridView在代码中实现分页和排序
- 常用的函数调用约定 stdcall/cdecl/fastcall
- EL 表达式用不了
- test1
- 10大网络命令
- Client-side data filtering with E4X and XMLListCollection
- Ext.form.FormPanel的扩展
- c# 实现控件拖拽
- 日常交际技巧经验总结99句(大全)
- PPC WM6.1智能手机上使用日语辞典浅谈
- 程序设计概述2
- Ext.util.MD5 基于js的MD5
- 求一段veb.net打印图片的代码
- 一种并行化游戏引擎的设计方案