vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.15k stars 1.38k forks source link

how to refresh data in custom method? #2535

Closed ghost closed 3 years ago

ghost commented 3 years ago

hello, thank for the useful js package. I have a question about contextmenu, for example i have the following custom method:

function customMenu(node) {
        // The default set of all items
        var items = {
            addItem: { // The "rename" menu item
                label: "Add new folder",
                action: function (node_data) {
                      // call api with ajax to add folder in backend
                     ....
                    //how do i trigger the callback to refresh the folder data?
                }
            }
        };

        return items;
    }

$(function () { 
        $('#jstree_demo_div').jstree({
            "plugins" : [ "contextmenu", "wholerow"],
            "contextmenu": {
                "items": customMenu
            },
            'core' : {
                'data' : {
                    "url" : "api-to-get-folder-datas",
                    "data" : function (node) {
                        return { "id" : node.id };
                    }
                },
                "check_callback" : true
            }
        });
    });

How can i refresh the table data within the custom method?

ghost commented 3 years ago

nvm i found out a way :)

$('#jstree_demo_div').jstree(true).refresh();

for any having the same problem