Sorting XML documents using an XMLListCollection
2008-01-13 14:31
405 查看
The following example shows how you can sort an XML document by converting it into an XMLListCollection and applying a sort. You can also easily reverse the current sort by calling the SortField object’s
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.utils.StringUtil;
private function list_labelFunc(item:Object):String {
return StringUtil.substitute("{0} {1} ({2} {3})",
item.@label, // city
item.@name, // name
item.parent().parent().@abbrev, // league
item.parent().@label); // division
}
private function checkBox_click(evt:MouseEvent):void {
sortField.reverse();
xmlListColl.refresh();
}
]]>
</mx:Script>
<mx:XML id="mlb" source="mlb.xml" />
<mx:XMLListCollection id="xmlListColl"
source="{mlb.league.division.team}">
<mx:sort>
<mx:Sort>
<mx:fields>
<mx:SortField id="sortField"
name="@label"
caseInsensitive="true" />
</mx:fields>
</mx:Sort>
</mx:sort>
</mx:XMLListCollection>
<mx:ApplicationControlBar dock="true">
<mx:CheckBox id="checkBox"
label="reverse()"
labelPlacement="left"
click="checkBox_click(event);" />
</mx:ApplicationControlBar>
<mx:List id="list"
dataProvider="{xmlListColl}"
labelFunction="list_labelFunc"
width="300"
rowCount="8" />
</mx:Application>
reverse()method and refreshing the XMLListCollection object
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/04/sorting-xml-documents-using-an-xmllistcollection/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.utils.StringUtil;
private function list_labelFunc(item:Object):String {
return StringUtil.substitute("{0} {1} ({2} {3})",
item.@label, // city
item.@name, // name
item.parent().parent().@abbrev, // league
item.parent().@label); // division
}
private function checkBox_click(evt:MouseEvent):void {
sortField.reverse();
xmlListColl.refresh();
}
]]>
</mx:Script>
<mx:XML id="mlb" source="mlb.xml" />
<mx:XMLListCollection id="xmlListColl"
source="{mlb.league.division.team}">
<mx:sort>
<mx:Sort>
<mx:fields>
<mx:SortField id="sortField"
name="@label"
caseInsensitive="true" />
</mx:fields>
</mx:Sort>
</mx:sort>
</mx:XMLListCollection>
<mx:ApplicationControlBar dock="true">
<mx:CheckBox id="checkBox"
label="reverse()"
labelPlacement="left"
click="checkBox_click(event);" />
</mx:ApplicationControlBar>
<mx:List id="list"
dataProvider="{xmlListColl}"
labelFunction="list_labelFunc"
width="300"
rowCount="8" />
</mx:Application>
相关文章推荐
- Sorting and filtering data in an XMLListCollection
- Using an XML data provider with the Spark List control in Flex 4
- An Extensive Examination of LINQ: Querying and Searching XML Documents Using LINQ to XML
- How to enable sorting on a GridView using an IEnumerable list as datasource
- 用delete删除XML和XMLListCollection的节点
- FLEX实践—XML、XMLList、XMLListCollection、ArrayCollection关系转换
- Flex之旅:第一部分:flex必备基础知识积累(7)---XML, XMLList, XMLListCollection的区别(三)
- How To Generate An XML File As A Target Datastore Using ODI In An Integration Interface ? [ID 454268
- Output an XML type attribute using DataContract
- #Paper Reading# An Information Retrieval Approach for Chatbot Engines Using Unstructured Documents
- Using an XmlAdapter
- 使用XMLLISTCOLLECTION 和ARRAYCOLLECTION对象的对比
- Noticed a strange thing the other day, a list has the property ItemCount and also an Items collection which has its own .Count b
- Building Word 2007 Documents Using Office Open XML Formats
- FLEX XML XMLList XMLListCollection ArrayCollection相互转换
- Flex--之XML、XMLLIST和XMLListCollection的关系和区别
- FLEX XML、XMLList、XMLListCollection、ArrayCollection关系转换
- FLEX XML XMLList XMLListCollection ArrayCollection相互转换
- FLEX实践—XML、XMLList、 XMLListCollection、ArrayCollection关系转换
- Flex之旅:第一部分:flex必备基础知识积累(5)---XML, XMLList, XMLListCollection的区别(一)