• Sorting XML documents using an XMLListCollection


    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 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>

  • 相关阅读:
    SpirngBoot整合Mybatis Plus多数据源
    SpringBoot整合EasyPoi 封装Excel导出通用工具类,行高自适应,导出图片
    阿里云服务器安装Docker Compose
    设置Docker容器里的时间
    坏代码导致的性能问题大赏:CPU占用飙到了900%!
    Java程序员涨薪必备的性能调优知识点,收好了!
    SprinMvc快速入门
    python中文乱码问题
    python中自定义函数类的引用(最全)
    datax
  • 原文地址:https://www.cnblogs.com/taobataoma/p/1036987.html
Copyright © 2020-2023  润新知