Dropout
Dropout

Reputation: 13866

Creating a JSTree node on a specific position in the tree

I am trying to update a JSTree structure on the open_node.jstree event. It should populate the children of the opened parent.

treeContent.jstree({
        "json_data": {"data": jsonData},
        "progressive_render": "true",
        "plugins": ["themes", "json_data", "ui", "checkbox"]
    })

In this part jsonData is the actual data loaded to the tree recieved from an Ajax call. I would like to bind an event like this:

.bind("open_node.jstree", function (event, data) {
                children = data.inst._get_children(data.rslt.obj);
                for (i = 0; i < children.length; i++) {
                    //this doesn't work
                    treeContent.jstree("create", children[i], "inside", getJSONData(children[i].getAttribute('path')));                        
                }
            });

By doesn't work I mean that the correct data is recieved from getJSONData, but the child element isn't altered.

Instead of the line that's not working I need to set the data for each child from the getJSONData() function. It returns data in the same format that's used when loading jsonData in the first place - a JSON object.

How can I do this please?

Upvotes: 3

Views: 1996

Answers (1)

Dropout
Dropout

Reputation: 13866

I've managed to achieve what I wanted, but it seems like a hack:

.bind("open_node.jstree", function (event, data) {
                children = data.inst._get_children(data.rslt.obj);
                for(var i=0; i<children.length; i++){
                    data.inst.create_node(data.rslt.obj, "inside", getJSONData(children[i].getAttribute('path')));
                    data.inst.delete_node(children[i]);
                }
            });

Upvotes: 1

Related Questions