cucucool
cucucool

Reputation: 3887

Populating tree in flex using array

Hi my required tree structure is as follows

a  -- b -- d
   |  |
   |  |
   |  -- e
   -- c

I have my string array as follows

a/b,c b/d,e d/ e

where the component before / represents parent and the children of the corresponding parent are separated by ,

Can anyone provide me the logic to create a array collection for this hierarchy to set as dataprovider to my tree.

Thanks and regards

Upvotes: 0

Views: 713

Answers (1)

Wade Mueller
Wade Mueller

Reputation: 6059

Here's the general idea. (I'm not going to type all of the nodes out) Another approach is to create an object that has label and children properties rather than creating all of this dynamically with Objects. Hope that helps.

var dp:Array = new Array();

dp[0] = new Object();
dp[0].label = "a";
dp[0].children = new Array();
dp[0].children[0] = new Object();
dp[0].children[0].label = "b";

myTree.dataProvider = dp;

Upvotes: 1

Related Questions