3.2.0

Tree Control - Multiple Levels

I know this must be easy, but I cannot get it to work, and the one example I found on the forum does not seem to work, either.

From the AW tree example:

var tree = {
0: [1, 2, 3, 4],
1: [5, 6],
2: [7],
3: [8],
4: [9]
}

I want to add another level - let's say on node 4. From the eample I found I think it should be:

var tree = {
0: [1, 2, 3, 4],
1: [5, 6],
2: [7],
3: [8],
4: [9: [10, 11]]
}

But I cannot get that to work.

Regards,
Brian
Brian Crandall
July 31,
OK. I played around a bit more and found that:

var tree = {
0: [1, 2, 3, 4],
1: [5, 6],
2: [7],
3: [8],
4: [9],
9: [10, 11]
}

works. Seems different from the example I found, but maybe I misinterpreted Alex's code/comments.

Brian Crandall
July 31,
It might help to understand what's going on.

In your first post the second example was wrong because of the way the AW code uses the associate array for the tree.

To understand the syntax for a JS associate array, read -
http://blog.persistent.info/2004/08/javascript-associative-arrays.html

Now each element in the assoc. array for the tree structure is expected to be an array. In your example that didn't work, 4: [9: [10, 11]] is incorrect because you are trying to put another assoc. array within the tree element array without defining the assoc. array correctly (i.e. syntax error).

However, even if you defined it correctly, it wouldn't work as its not what the AW code expects.

The code expects the array element to contain either a list or a single value. If its a single value, its either the element label for another element in the tree's assoc. array or a list with one element.

So 4:[9] means look up element label 9 to find the array list (or use 9 as the value if there's no matching element label in the assoc. array).

The confusion stems from the fact that the code uses numbers for the labels. I don't know if strings would work but it would appear not since the labels are used to index into the ItemText and ItemImage arrays assigned to the tree.
Anthony
July 31,

This topic is archived.

See also:


Back to support forum