Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with xml + Tree()

    hi , want to utilize this xml snippet and not sure how to put it together with mx:Tree()
    :


    <menu-main-items type="array">

    <menu-main-item>

    <created-at type="datetime" nil="true"/>

    <id type="integer">27</id>

    <menu-main-id type="integer">3</menu-main-id>

    <parent-id type="integer" nil="true"/>

    <title>Sales-root</title>

    <title-alt nil="true"/>

    <updated-at type="datetime" nil="true"/>

    <children type="array">

    <child type="MenuMainItem">

    <created-at type="datetime" nil="true"/>

    <id type="integer">1</id>

    <menu-main-id type="integer">3</menu-main-id>

    <parent-id type="integer">27</parent-id>

    <title>Accounts</title>

    <title-alt nil="true"/>

    <updated-at type="datetime" nil="true"/>

    </child>

    <child type="MenuMainItem">

    <created-at type="datetime" nil="true"/>

    <id type="integer">2</id>

    <menu-main-id type="integer">3</menu-main-id>

    <parent-id type="integer">27</parent-id>

    <title>Contacts</title>

    <title-alt nil="true"/>

    <updated-at type="datetime" nil="true"/>

    </child>

    <child type="MenuMainItem">

    <created-at type="datetime" nil="true"/>

    <id type="integer">3</id>

    <menu-main-id type="integer">3</menu-main-id>

    <parent-id type="integer">27</parent-id>

    <title>Oppertunities</title>

    <title-alt nil="true"/>

    <updated-at type="datetime" nil="true"/>

    </child>

    <child type="MenuMainItem">

    <created-at type="datetime" nil="true"/>

    <id type="integer">4</id>

    <menu-main-id type="integer">3</menu-main-id>

    <parent-id type="integer">27</parent-id>

    <title>Leads</title>

    <title-alt/>

    <updated-at type="datetime" nil="true"/>

    </child>

    </children>

    </menu-main-item>

    </menu-main-items>



    ==========================================

    <mx:HTTPService id="id_http_menumain_tree" method="GET"

    resultFormat="e4x"

    result="resultHandler_NavTree(event);" fault="onFault(event);" >

    <mx:request xmlns="">

    <id>{m_vboxex_id}</id>

    </mx:request>

    </mx:HTTPService>

    ==========================================

    private function resultHandler_NavTree(event:ResultEvent):void {



    trace("resultHandler_NavTree");

    trace(XML(event.result));



    var result:XML = XML(event.result);

    var xmlList:XMLList = result.children();

    //var xmlList:XMLList = result.child(String("menu-main-item"));

    //trace(xmlList.length());

    var m_httpresultdata:XMLListCollection = new XMLListCollection(xmlList);





    var tree:Tree = new Tree();

    //tree.dataProvider = id_http_menumain_tree.lastResult;

    //tree.dataProvider = m_httpresultdata;



    tree.dataProvider = result;

    //tree.labelFunction = labelFunc;

    tree.labelField = "@title";

    tree.showRoot = false;


    thx

  • #2
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's a number of things to fix here, Tom.

    Firstly, don't use dashes in your node names. AS will try to resolve those as operators, and won't parse them correctly as E4X.

    Secondly, "@title" selects node attributes, not children.

    Thirdly, and this is semantic I know, but avoid using reserved keywords as your node names, i.e. "child" and "children".

    Fourthly, the Tree component will try to emulate your node structure as a folder structure, which means that nesting your MainMenuItems inside the main-menu-item.children nodes will create an extra, unnecessary folder.

    Finally, you misspelled "Opportunities".

    I used a watered-down version of your xml (sans the HTTPService for testing purposes, that code looked fine to me) and I think this might be more the results you're looking for:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
    	<mx:XML xmlns="" id="dataXML">
    		<mainMenuItems type="array">
    		    <mainMenuItem title="Sales-root">
    	            <childItem type="MenuMainItem" title="Accounts" />
    	            <childItem type="MenuMainItem" title="Contacts" />
    	            <childItem type="MenuMainItem" title="Opportunities" />
    	            <childItem type="MenuMainItem" title="Leads" />
    		    </mainMenuItem>
    		</mainMenuItems>
    	</mx:XML>
    	<mx:Tree id="menuTree" width="25%" height="100%" dataProvider="{dataXML.mainMenuItem}" labelField="@title" />
    </mx:WindowedApplication>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •