Ok, so this shouldn't be difficult, however I have encountered weird and bizarra flukes.
I am trying to pack a tree into an array, where each node is something like:
- title: string-for-display
- key: id-value
- children: array of child nodes
the fluke is so strange I can't comprehend it at all: when I try to add a child to a node, I do something like
if(node.children == undefined) {
node.children = new Array();
}
node.children.push({ title: value, key: key });
this was deleting some previously inserted nodes....so I did some debugging and found that this code:
if(node.children == undefined) {
node.children = new Array();
}
was at fault, which doesn't make any sense at all - node.children = new Array() shouldn't delete ANYTHING if node.children is undefined......, right?
Am I doing something wrong? if so, how do I pack the tree into an array in Javascript?