3 Replies Latest reply on Oct 31, 2010 10:22 PM by SrinivasanJR

    Adding Node and Deleting Node in Tree

    SrinivasanJR Level 1

      Hi,

      I am building a tree dynamically.

       

      I have a class which has set of properties.I am constructing as follows.

       

      public class TreeNode
          {
              public function TreeNode()
              {
              }
           public var friendlyName:String;
           public var icon:Class;
           [Bindable]
           public var children : Array;
           public var logicalName:String;
           public var neType:String;
          
           [Bindable]
           public var arrayColl:ArrayCollection = new ArrayCollection();
         
          
           public function addChild(node:TopoTreeNode):void
           {
               if (this.children == null){
                   this.children = new Array();
               }
               children.push(node);
               arrayColl.source = children;    
           }
          
           public function clearChild():void
           {
               children = null;
           }
          
           public function removeChild(arrayIndex:int):void
           {
               if(children != null)
               {
               children.splice(arrayIndex,1);
               arrayColl.source = children;
               }
           }

       

      Then I set the dataProvider as follows where treeModel is object that is injected.

       

       

      <mx:Tree id="tree"
                   dataProvider="{treeModel.rootNode.arrayColl}"
                   labelFunction="{treeModel.getDisplayName}"
                   iconFunction="{treeModel.setIcon}"
                   width="100%"
                   height="95%"
                   rowCount="6"
                   showScrollTips="true" showDataTips="true" dataTipFunction="{treeModel.getDisplayName}" allowMultipleSelection="true" click="treeModel.displayItemInWorkingView(tree.selectedItems);"/>

       

       

      TreeModel has the following variables

       

              [Bindable]
              public var rootNode:TopoTreeNode = new TopoTreeNode(); // this is the rootNode.
             
              [Bindable]
              public var rootChild:TopoTreeNode = new TopoTreeNode(); // this is the child of the root node..

      While constructing the tree, it is working fine.

       

      But after this when i try to add a node (ie adding a node as child to rootNode), it is getting added to my rootNode object but it is not getting displayed

       

      When i click on the items in the tree or click on the drop menu in the tree it is getting displayed.

       

      But i want it to be shown in the tree without clicking anything.

       

      Could anyone help on this?

       

      Regards

      Srini