Flex中利用mx:Sort和mx:SortField对XMLListCollection进行排序的例子

By Minidxer | July 23, 2008

接下来的例子演示了Flex中如何通过<mx:Sort />和<mx:SortField />对XMLListCollection进行排序。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:XML id="myXML" source="http://feeds.feedburner.com/FlexExamples?format=xml" format="e4x" />
  8.     <mx:XMLListCollection id="xlc" source="{myXML..item.category}" sort="{mySort}" />
  9.  
  10.     <mx:Sort id="mySort">
  11.         <mx:fields>
  12.             <mx:SortField name="*" caseInsensitive="true" />
  13.         </mx:fields>
  14.     </mx:Sort>
  15.  
  16.     <mx:VBox horizontalAlign="left">
  17.         <mx:Label text="Categories ({xlc.length}):" />
  18.         <mx:List id="list"
  19.                 dataProvider="{xlc}"
  20.                 rowCount="5"
  21.                 width="200"
  22.                 creationComplete="{xlc.refresh()}" />
  23.     </mx:VBox>
  24.  
  25. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer

Topics: Flex | Tags: , , , ,

Related Post

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

Archives

Sponsored Ads