I have some trouble with a recursive function for creating a TreeView (using MetroUI) from some XML-Data. In the first scope, so the first level of the Tree, is created as expected, but the second one is not created. My XML-data has the following structure:
<tree>
<sitenode>
<name>First Element</name>
<children>
<sitenode>
...
</sitenode>
</children>
</sitenode>
</tree>
The JavaScript-Code I am using is this one:
var tree = $('#dlgEditorCreateNewSiteSelParent').data('treeview');
/* Helper-function for Recursion */
function dlgEditorCreateNewSiteCreateParentTreeViewNodes(nodes, parent) {
var i, j;
/* Alle knoten durchlaudfen */
for (i = 0; i < nodes.length; i++) {
/* Add leaf */
var node = tree.addLeaf(parent, $(nodes[i]).find('>name').text());
/* Children */
var children = $(nodes[i]).find('children > sitenode');
for (j = 0; j < children.length; j++) {
/* REKURSION */
//alert('childre child nr. '+j+' with name '+$(children[j]).find('> name').text());
dlgEditorCreateNewSiteCreateParentTreeViewNodes(children[j], node);
}
}
}
var roots = $(result).find('tree > sitenode');
dlgEditorCreateNewSiteCreateParentTreeViewNodes(roots, false);
I have already searched for some comparable problems, but everything I found was about the counter-variables scope.