Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function to expand a parent node dynamically from json in a dhtmlx tree

On the dhtmlx documentation, I see this:

The following method is responsible for specifying the way server side URL is constructed during dynamical loading calls:

<script>
    tree.setXMLAutoLoadingBehaviour(mode);
</script>

The following modes variants are available here:

function - is used for calling user-defined handler that should be set as the first parameter of setXMLAutoLoading() method.

So I understand that I need to write a function to add one layer of children to the actual node (the selected node), if it has children. But what I don't understand, is how I should do this, as I have some difficulty finding the right parameters to use, to be able to find the children and add them to the tree.

I am loading a local json file, with .loadJSON("data.json");. Right now, I know I should change the behavior to function and call a function that will load the children of the clicked/expended node. I've named that function loadBranch in the code below.

myTree.setXMLAutoLoadingBehaviour("function");
myTree.setXMLAutoLoading(function (id) { loadBranch(id)});

But I am not able to write a function that will only find and add those children into my dhtmlx tree. Could any of you give me a code snippet that could be used as this function?

Thanks anyway.

PS: My "ultimate" goal is to create a default dhtmlx tree that can load a json dynamically, to compare it's performance with other trees.

like image 988
David Gourde Avatar asked Mar 08 '26 02:03

David Gourde


1 Answers

Try something like this:

mytree.setXMLAutoLoadingBehaviour("function");
mytree.setXMLAutoLoading (function(id){
    // here based on ID you need to load some XML
    mytree.loadXML(myFunction(id));
});
like image 188
Viv Avatar answered Mar 09 '26 15:03

Viv