Sorting and filtering data in an XMLListCollection

简介:
The following code is a brief example of sorting a Flex XMLListCollection using the Sort and SortField classes, and the  XMLListCollection.sort  property. We also look at filtering the XMLCollection using a custom filter function.
<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white"
        creationComplete
="init()" >

    
< mx:Script >
        
<![CDATA[
            import mx.collections.SortField;
            import mx.collections.Sort;
            import mx.controls.*;

            private function init():void {
                describeTypeXML = describeType(DataGrid);
                factoryMethodsXLC.source = describeTypeXML.factory.method;
            }

            private function sortXLC():void {
                var nameSort:Sort = new Sort();
                nameSort.fields = [new SortField('@name', true)];

                factoryMethodsXLC.sort = nameSort;
                factoryMethodsXLC.refresh();
            }

            private function filterXLC():void {
                if (filterCh.selected) {
                    factoryMethodsXLC.filterFunction = declaredBy_filterFunc;
                    factoryMethodsXLC.refresh();
                } else {
                    factoryMethodsXLC.filterFunction = null;
                    factoryMethodsXLC.refresh();
                }
            }

            private function declaredBy_filterFunc(item:XML):Boolean {
                return item.@declaredBy == describeTypeXML.@name;
            }
        
]]>
    
</ mx:Script >

    
< mx:XML  id ="describeTypeXML"   />

    
< mx:XMLListCollection  id ="factoryMethodsXLC"   />

    
< mx:VBox >
        
< mx:DataGrid  id ="factoryMethodsGrid"
                dataProvider
="{factoryMethodsXLC}"
                width
="400"
                rowCount
="7" >
            
< mx:columns >
                
< mx:DataGridColumn  dataField ="@name"   />
                
< mx:DataGridColumn  dataField ="@returnType"   />
                
< mx:DataGridColumn  dataField ="@declaredBy"   />
            
</ mx:columns >
        
</ mx:DataGrid >
        
< mx:HBox  width ="100%" >
            
< mx:Button  id ="sortBtn"
                    label
="Sort ({factoryMethodsGrid.dataProvider.length} items)"
                    click
="sortXLC()"   />
            
< mx:Spacer  width ="100%"   />
            
< mx:CheckBox  id ="filterCh"
                    label
="{describeTypeXML.@name} only"
                    click
="filterXLC()"   />
        
</ mx:HBox >
    
</ mx:VBox >

</ mx:Application >




    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2008/01/10/1034065.html ,如需转载请自行联系原作者

相关文章
|
5月前
(145) Table ‘./addon_collect_wukong_spider‘ is marked as crashed and should be repaired解决思路
(145) Table ‘./addon_collect_wukong_spider‘ is marked as crashed and should be repaired解决思路
25 0
|
6月前
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
121 5
解决Mapped Statements collection already contains value for experiment4.UserMapper.listUser错误~
解决Mapped Statements collection already contains value for experiment4.UserMapper.listUser错误~
|
算法 搜索推荐 数据库
一个有点咬文嚼字的 sorting 和 ordering
为什么排序算法的英文是 sorting 而不是 ordering。
138 0
|
自然语言处理
Re24:读论文 IOT-Match Explainable Legal Case Matching via Inverse Optimal Transport-based Rationale Ext
Re24:读论文 IOT-Match Explainable Legal Case Matching via Inverse Optimal Transport-based Rationale Ext
Re24:读论文 IOT-Match Explainable Legal Case Matching via Inverse Optimal Transport-based Rationale Ext
|
机器学习/深度学习 计算机视觉
Re14:读论文 ILLSI Interpretable Low-Resource Legal Decision Making
Re14:读论文 ILLSI Interpretable Low-Resource Legal Decision Making
Re14:读论文 ILLSI Interpretable Low-Resource Legal Decision Making
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
101 0
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
119 0
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
145 0
成功解决 ValueError: feature_names mismatch training data did not have the following fields
成功解决 ValueError: feature_names mismatch training data did not have the following fields
下一篇
无影云桌面