Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsTree Object has no method addBack

This is my instantiation code for the jsTree.

$("#folder_tree").jstree({
    "themes" : {
        "theme" : "default",
        "dots" : true,
        "icons" : true
    },
    "json_data" : {
        "ajax" : {
            "url" : "/portal/folders",
            "data" : function(n) {
                if ($(n[0]).find("a").attr("id")) {
                    console.log($(n[0]).find("a").attr("id").split('_')[1]);
                    return {
                        "id" : $(n[0]).find("a").attr("id").split('_')[1]
                    };
                }
                return { "id" : "0" };
            }
        }
    },
    "plugins" : [ "themes", "json_data", "ui", "contextmenu", "dnd", "search", "crrm" ]
}).bind("select_node.jstree", function(e,data) {
    console.log(data.rslt.obj.context.id);
});

It loads the data correctly on the first load (the 0 case), but then when I click to expand any of the folders, it is giving me the error:

Uncaught TypeError: Object [object Object] has no method 'addBack' 

Even though the correct id of the expanded node is being logged to the console and the ajax request is being made to the server correctly. Notice also that I have to use a fairly horrific kludge to find the id of the element due to the fact that the documented code produces nothing but errors for me (and I am using the same version of jsTree as the documentation) when trying to access n.attr("id"). Plus, under bind("select_node"... I have to use a non-documented function to find the id again. After hours of troubleshooting, I'm still completely baffled, but something is clearly not operating correctly.

like image 940
tufelkinder Avatar asked Dec 15 '22 13:12

tufelkinder


1 Answers

Make sure you are using jQuery 1.8 or later. addBack wasn't added until then.

like image 68
cdmckay Avatar answered Dec 28 '22 02:12

cdmckay