View Full Version : Treenodes in an array gets corrupted

8 Oct 2009, 11:46 PM

Objective: I need to be able to access each of the tree nodes very often, and to prevent searching for a specific node all the time, I want to keep a reference to each node.

Solution: I generate each treenode and the tree structure, and store each treenode in an array.

Problem: When assigning a treenode from the array, as a child of another treenode, the assigned child becomes corrupted. If I assign the same treenode stored in a separate variable, it works fine.

Is this approach wrong or is it maybe my limited Javascript knowledge?

Kind regards, Casper

My setup:

var nodeCollection = new Array(2);

nodeCollection[0] = createLayerNode("Node number 1");
nodeCollection[1] = createLayerNode("Node number 2");

var node1 = createLayerNode("Node number 1");
var node2 = createLayerNode("Node number 2");

var baseRoot = new Ext.tree.TreeNode(
text: "Folder",
leaf: false

// Does not work...

// Does work...

// Populate the root.
var rootNode = new Ext.tree.TreeNode(
leaf: false,
text: "Root",
expandable: true,
expanded: true


function createLayerNode(title) {
var node = new Ext.tree.TreeNode(
leaf: true,
text: title

return node;