4 Replies Latest reply on Aug 14, 2009 8:32 AM by Jed Schneider

    Walking the Tree

    Zolotoj Level 3

      Here is a sample of my tree:

       

      <menu name="46950 - MISSION ALLERGY" menuid="1" parentid="" link="" line_id="" salesrepid="" category="" folder="1">
        <menu name="COMMITMENTS" menuid="5" parentid="1" link="" line_id="" salesrepid="" category="" folder="1">
          <menu name="SHEET SET 060507.XLS" menuid="6" parentid="5" link="" line_id="" salesrepid="" category="" folder="0"/>
          <menu name="SHEET SETS 061908.XLSX" menuid="7" parentid="5" link="" line_id="" salesrepid="" category="" folder="0"/>
        </menu>
        <menu name="CORRESPONDENCE" menuid="8" parentid="1" link="" line_id="" salesrepid="" category="" folder="1">
          <menu name="2006" menuid="12" parentid="8" link="" line_id="" salesrepid="" category="" folder="1">
            <menu name="052406 400 TENCEL LYOCELL STRIPE SHEET SET.DOC" menuid="13" parentid="12" link="" line_id="" salesrepid="" category="" folder="0"/>
          </menu>
      .....
      

       

      I am starting walking out of it from:

       

      <menu name="052406 400 TENCEL LYOCELL STRIPE SHEET SET.DOC" menuid="13" parentid="12" link="" line_id="" salesrepid="" category="" folder="0"/>
      

       

      Here is my code:

       

      var parentArray:Array = new Array();
      var fullPath:String = "";
      parentArray.push(tree.selectedItem.@name);
      var parent:Object = tree.getParentItem(obj); 
      while(parent != null)
      {
        parentArray.push(parent["@name"]);
        obj = parent;
        parent = tree.getParentItem(obj); 
      }
      

       

      at the end parentArray will not have a root parent: "46950 - MISSION ALLERGY" becasue

      tree.getParentItem(obj) will return null for menuid="8". Why is that?

       

      Thanks

        • 1. Re: Walking the Tree
          Jed Schneider Level 1

          i assume you are getting this xml from a httpService call and your resultFormat is set to e4x, so put your xml inside a root tag, like <allMenus>. ResultEvent.event.result.menu will give you an xmlList of all your menus. then menus:XMLList = event.result.menu and menus[0] is the menu you are looking for.

          • 2. Re: Walking the Tree
            Zolotoj Level 3

            Yes, I understand that adding another "root" will help. But why it's not working in my case? Why do we need extra root?

            • 3. Re: Walking the Tree
              Zolotoj Level 3

              I think this is the right way:

              parentArray.push(tree.selectedItem.@name);
              var parent:Object = tree.getParentItem(obj);
              while(parent != null)
              {
                parentArray.push(parent["@name"]);
                obj = parent; 
                parent = tree.getParentItem(parent); 
              }
              // add root name
              parent = obj.parent();
              parentArray.push(parent.@name);
              

              • 4. Re: Walking the Tree
                Jed Schneider Level 1

                well, first I'd make sure your xml passes validation, since it wont in the code snippet that you posted.

                 

                Then I'd maybe try to do something like event.result.children(), its just a guess, but that should return an XML list, you may have to cast it first myXMLList = event.result as XMLList, hope that helps.