4 Replies Latest reply on Apr 1, 2010 10:07 AM by JockMahon

    populating a Tree

    JockMahon Level 1

      Iv a tree that i want to populate with a  result set from the server.

       

      This rs will have rows where each row will be catergoised , so current , sent , failed etc

       

      I need to populate the tree so that it will look some thing like

       

      current

           Order 1

           Order 2

      Sent

           Sent 1

           Sent 2

      Failed

           Failed 1

           Failed 2

       

      how can i do this

        • 1. Re: populating a Tree
          Skiadzo

          this is a way to do it. It uses an xml entity that you construct and control.

          I use something similar in an app on which I am working. In that application, I put the mx:Tree at the first element of mx:HDividedBox container, followed by a mx:VBox containing a mx:ViewStack. If all of your content looks the same, you can skip the mx:ViewStack.

           

           

          <mx:XMLList id="treeData">

          <node label='top'>

          <node label='current'

          <!-- add current content so that has the following form -->

               <node label='Order 1'/>

               <node label='Order 2'/>

          </node>

          <node label='Sent'

          <!-- add sent content -->

          </node>

           

          <node label='Failed'>

          <!-- add failed content -->

          </node>

          </node>

          </mx:XMLList>

          <mx:Tree id="myTree" showRoot="false" dataProvider="{treeData}" change="treeChanged(event)" />

          <mx:Script><![CDATA[

          // Event handler for the Tree control change event.

          private function treeChanged(event:Event):void

          {

               var selectedNode:XML =Tree(event.target).selectedItem as XML;

               var label:String = selectedNode.@label; // or add your own attribute

               // do something

          }

           

          ]]></mx:Script>

          Hope this helps.

          1 person found this helpful
          • 2. Re: populating a Tree
            JockMahon Level 1

            how do u build up a dynamic xml, can u do

             

            <mx:XMLList id="treeData">

            <node  label='top'>

            <node label='current'

             

            for( var i = 0 ; i < 10 ; i++)

            {

                  <node label='Order i'/>

            }

            </node>

            • 3. Re: populating a Tree
              Skiadzo Level 1

              Hmm. Probably not.

              Consider...

              create the variable treeDate via

              <mx:XMLLIST id='treeData'/>

               

              then in your code:

              var top:XML = <node label='Top'/>

              treeData.appendChild(top);

              var currentBranch:XML = <node label='current'/>

              top.appendChild(currentBranch);

              var leafNode:XML;

              var label:String;

              //loop

              leafNode = <node label={label}/>

              currentBranch.appendChild(leafNode);

              //end loop

               

              Now, this is a code sketch, so salt & pepper to taste.

              • 4. Re: populating a Tree
                JockMahon Level 1

                thanks iv have got this working by doing the following

                 

                            var xm:XML = <Orders></Orders>;
                           
                            var ordersArray:Object = new Object();
                            ordersArray["1"] = "<node label='Current' templateID='1'>";
                            ordersArray["3"] = "<node label='Sent' templateID='3'>";
                            ordersArray["5"] = "<node label='Failed' templateID='5'>";

                 

                         for(var i:uint = 0 ; i < event.result.length ; i++)
                         {
                       ordersArray[String( event.result.getItemAt(i)["ORDER_STATUS_ID"] ) ] += '<node label="' + event.result.getItemAt(i)["TEMPLATE_NAME"] + '" ';
                       ordersArray[String( event.result.getItemAt(i)["ORDER_STATUS_ID"] ) ] += 'templateID="' + event.result.getItemAt(i)["ORDER_TEMPLATE_ID"]+ '"/>';
                            }

                            ordersArray["1"] += "</node>";
                            ordersArray["3"] += "</node>";
                            ordersArray["5"] += "</node>";
                           
                            for(var j:String in ordersArray )
                            {
                                var xmlList:XMLList = XMLList(ordersArray[String(j)]);
                                xm.appendChild(xmlList);
                            }