4 Replies Latest reply on Mar 17, 2011 2:00 AM by y-volk

    Expand tree node dynamically

    Benoitcn Level 1

       

      I try filter the xml and open the tree node.
      var item:XML = xml..node.(@BH == argument); // item is not null !
      tree.openItems = item; // not worked
      tree.expandItem(item); // also not worked
      tree.expandChildrenOf(item); // still not worked
      var p:* = tree.getParentItem(item); //p is always null !!!~~~
      tree.expandChildrenOf(p);

       

        • 1. Re: Expand tree node dynamically
          y-volk Level 1

          You should try to open the tree node in the way I've provided below:

           

          [Bindable]
          private var xmlSource: XML;

           

          protected function application1_creationCompleteHandler(event: FlexEvent): void
          {
          xmlSource =
          <item id="0">
          <item id="1">item1</item>
          <item id="2">
          <item id="21">item21</item>
          <item id="22">item22</item>
          </item>
          </item>;
          }

           

          protected function button1_clickHandler(event:MouseEvent):void
          {
          var nodes: XMLList = xmlSource..item.(@id == "21");

          if (nodes.length() > 0)
          {
          var parentNode: XML = nodes[0];

          while (parentNode.parent()) {
          tree.expandItem(parentNode.parent(), true);
          parentNode = parentNode.parent();
          }

          tree.expandItem(nodes[0], true);
          }
          }

          • 2. Re: Expand tree node dynamically
            eprevot123 Level 2

            you can try tree.openItems  = item.descendants or item.parent().descendants

            • 3. Re: Expand tree node dynamically
              Benoitcn Level 1

              Thanks, y-volk. My code like this, it's not worked fo

               

              if( this.argument != null && this.argument != '' ){

              //     var xml:XMLList = (tree.dataProvider as XMLListCollection).source;

                   var xml:XML= srv.lastResult as XML; // I can get the data.

                   var nodes:XMLList = xml..*.(@BH==argument);

                   if( nodes.length() > 0 ){

                    var PNode:XML = nodes[0];

                     

                    while( PNode.parent() ){

               

                     tree.expandItem(parentNode.parent(), true); // not worked

                     //tree.expandChildrenOf(PNode.parent(), true); // not worked

                     PNode = PNode.parent();

                    }     

                        tree.expandItem(parentNode.parent(), true);

               

              //tree.expandChildrenOf(PNode[0], true);// not worked    

                   }

                  }

              • 4. Re: Expand tree node dynamically
                y-volk Level 1

                The code you posted is slightly different from the one i proposed, after a while statement scope you need to call expandItem for nodes[0] item:

                 

                tree.expandItem(nodes[0], true)

                 

                So you need to try to replace  two rows which are placed below to the one placed above.

                tree.expandItem(parentNode.parent(), true);

                //tree.expandChildrenOf(PNode[0], true);// not worked