Search Tree node is to search XML with XPath : Tree Data « Components « Flex






Search Tree node is to search XML with XPath

Search Tree node is to search XML with XPath
      

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle">
    <mx:Script>
        
            import mx.controls.Alert;
            import mx.collections.XMLListCollection;
        
            [Bindable]
            private var searchResult:XMLList;
            private var searchResultIndex:uint = 0;

            private function findByName(event:MouseEvent):void
            {
                var searchStr:String = "A1";
                tree.expandChildrenOf(data[0], false);
                searchResult = data.node.node.(@name.toLowerCase().search(searchStr.toLowerCase()) > -1);
                searchResultIndex = 0;
                if (searchResult[searchResultIndex] != undefined)
                    expandNode(searchResult[searchResultIndex]);

                tree.expandChildrenOf(data[searchResultIndex], false);
                searchResultIndex += 1;
                if (searchResult[searchResultIndex] != undefined)
                    expandNode(searchResult[searchResultIndex]);
            }
            private function expandNode(xmlNode:XML):void
            {
                while (xmlNode.parent() != null) {
                    xmlNode = xmlNode.parent();
                    tree.expandItem(xmlNode, true, false);
                    tree.selectedItem = searchResult[searchResultIndex];
                }
            }
      
    </mx:Script>
    
    <mx:XMLList id="data">
        <node>
            <node name="A">
                <node name="A1" surname="a1" age="21" wage="1200"/>
                <node name="A2" surname="a2" age="22" wage="1000"/>
                <node name="A3" surname="a3" age="23" wage="1200"/>
                <node name="A4" surname="a4" age="24" wage="1500"/>
            </node>
            <node name="B">
                <node name="B1" surname="b1" age="21" wage="1900"/>
                <node name="B2" surname="b2" age="22" wage="1500"/>
                <node name="B3" surname="b3" age="23" wage="1200"/>
            </node>
            <node name="C">
                <node name="C1" surname="c1" age="29" wage="1500"/>
                <node name="C2" surname="c2" age="45" wage="1500"/>
                <node name="A1" surname="c3" age="25" wage="1300"/>
            </node>
        </node>
    </mx:XMLList>
    
    <mx:VBox>
            <mx:Button label="Search by name" click="findByName(event)" />  
        
        <mx:Tree id="tree" width="100%" height="100%" 
            showRoot="false" dataProvider="{data}" 
            labelField="@name" />
    </mx:VBox>

</mx:Application>

   
    
    
    
    
    
  








Related examples in the same category

1.XML data for Tree viewXML data for Tree view
2.Reference XML attribute for tree dataReference XML attribute for tree data
3.Set dataProvider for Tree control through xml attributeSet dataProvider for Tree control through xml attribute
4.Using XML data models and use it as data for Tree controlUsing XML data models and use it as data for Tree control
5.Tree data is from XMLListCollectionTree data is from XMLListCollection
6.Use ActionScript to set up the data provider for Tree controlUse ActionScript to set up the data provider for Tree control
7.Fill XML data into Tree and get it back when selectedFill XML data into Tree and get it back when selected
8.AdvancedDataGrid with Grouping(A tree table).AdvancedDataGrid with Grouping(A tree table).
9.Tree uses an XMLListCollection object as the data source:Tree uses an XMLListCollection object as the data source:
10.Tree with static dataTree with static data
11.Hierarchical AdvancedDataGrid Tree Column(TreeTable)Hierarchical AdvancedDataGrid Tree Column(TreeTable)
12.Use an XML object and Tree controlUse an XML object and Tree control
13.Tree control and XMLListCollectionTree control and XMLListCollection
14.Build Tree from XMLListCollection
15.Build a tree out of an XML documentBuild a tree out of an XML document
16.Tree controls uses an XML object directlyTree controls uses an XML object directly
17.Create Tree object from XMLListCreate Tree object from XMLList
18.Tree with static valueTree with static value