Selecting node after jstree refresh

1,321 views
Skip to first unread message

Tomi

unread,
Oct 28, 2014, 5:05:38 AM10/28/14
to jst...@googlegroups.com
Hi,

I have a following contextmenu action:

items = {
        "addDo": { "label": "Add Do",
            "action": function (node) {
                $.ajax({
                    type: 'POST',
                    url: '/Conclusion/SaveDo',
                    data: 'id=' + id,
                    success: function (data) {
                        $('#treeview').jstree(true).refresh();
                        $('#treeview').jstree(true).select_node(data.IdForTree);
                    }
                });
            }
        }
};

Ajax - call creates new item to data source, which is loaded to jsTree like this:

"core": {
            "check_callback": true,
            "data":
                {
                    "url": "/Conclusion/GetTreeData",
                    "type": "POST",
                    "dataType": "json",
                    "data": function (node) { return { "id": node.id }; }
                }
        }

Tree is updated correctly after the refresh, but node selection is not working.
I would like to select newly created item from the tree without success.

What I'm doing wrong?

Ivan Bozhanov

unread,
Oct 28, 2014, 8:04:19 AM10/28/14
to jst...@googlegroups.com
First of all, do you get any errors in the console? Because it is not obvious where data comes from.
Aside from that - the code will not work, because refresh may need to make a few async calls, which means the nodes will not be available right away - it depends on your tree config & data.
"refresh" takes a callback argument - use that, or the refresh.jstree event (using jQuery's "one" method which executes a handler only once).

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages