Flex中利用mx:Sort和mx:SortField对XMLListCollection进行排序的例子
By Minidxer | July 23, 2008
接下来的例子演示了Flex中如何通过<mx:Sort />和<mx:SortField />对XMLListCollection进行排序。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:XML id="myXML" source="http://feeds.feedburner.com/FlexExamples?format=xml" format="e4x" />
- <mx:XMLListCollection id="xlc" source="{myXML..item.category}" sort="{mySort}" />
- <mx:Sort id="mySort">
- <mx:fields>
- <mx:SortField name="*" caseInsensitive="true" />
- </mx:fields>
- </mx:Sort>
- <mx:VBox horizontalAlign="left">
- <mx:Label text="Categories ({xlc.length}):" />
- <mx:List id="list"
- dataProvider="{xlc}"
- rowCount="5"
- width="200"
- creationComplete="{xlc.refresh()}" />
- </mx:VBox>
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer
Topics:
Flex |
Tags: sort, SortField, XML, XMLListCollection, 排序