Hi i’m working on a Symfony project and i need the JsTree structure to represent hierarchies from a database. I declare the <ul> & <li> structure espected by the JsTree libray correctly. Each <li> has its id = the id of the corresponding element in database, I put an <a> with its href=[the url i need to use when click]. Then i use the following function:
$("#myTree").bind("select_node.jstree",function(event,data){
if(data.rslt.obj.attr("id")!=0){
window.location = "myModule/myAction?id="+data.rslt.obj.attr("id");
}
});
The problem is that the link does not work as espected. When i click, window.location adds “myModule/myAction?id=”+”the selected id” at the end of the route.
When i try more complex ways to indicate the new route to go to, for example window.location = <?php echo url_for("myModule/myAction")?>+"/id/"+data.rslt.obj.attr("id"); then the representation of the tree fails: it does not show like a tree, just as a list.
I think it would be possible if there is some way to do something like that:
window.location = data.rslt.obj.attr("id").subelement("a").attr("href"); then i could access to the information contained in the <li> field.
Thank you very much for your time.
I finaly found the answer. There is a function called
childNodesthat returns all the subelements of an object. I used the code below:var id = data.rslt.obj.attr("id");var child = document.getElementById(id).childNodes[1].firstChild;see documentation: childNodes doc