Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So, what is the actual problem you're having? </p> <p>It appears to me that you're not actually creating any children in your dataProvider. Each object should have children. This is your code, slightly modified, but completely runnable version of your code: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)"&gt; &lt;fx:Declarations&gt; &lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt; &lt;/fx:Declarations&gt; &lt;fx:Script&gt; &lt;![CDATA[ import mx.collections.ArrayCollection; import mx.events.FlexEvent; [Bindable] public var data : Array = ([ {objectID:1, parentID:null}, {objectID:10, parentID:null}, {objectID:8, parentID:null}, {objectID:6, parentID:null}, {objectID:5, parentID:6}, {objectID:4, parentID:6}, {objectID:9, parentID:6}, {objectID:2, parentID:6}, {objectID:11, parentID:7}, {objectID:7, parentID:8}, {objectID:5, parentID:8}, ]); [Bindable] public var dataProvider : Array; protected function application1_creationCompleteHandler(event:FlexEvent):void { // TODO Auto-generated method stub setDataProvider(data); } public function setDataProvider(data:Array):void { var tree:Array = new Array(); for(var i:Number = 0; i &lt; data.length; i++) { // do the top level array if(!data[i].parentID) { data[i].children = getChildren(data[i].objectID, data); tree.push(data[i]); } } function getChildren(objectID:Number, data:Array):Array { var childArr:Array = new Array(); for(var k:Number = 0; k &lt; data.length; k++) { if(data[k].parentID == objectID) { childArr.push(data[k]); //getChildren(data[k].objectID, data); } } return childArr; } // trace(ObjectUtil.toString(tree)); dataProvider = tree; } ]]&gt; &lt;/fx:Script&gt; &lt;mx:Tree id="treeObject" dataProvider="{dataProvider}" /&gt; &lt;/s:Application&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload