最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jsTree Object has no method addBack - Stack Overflow

programmeradmin4浏览0评论

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 pletely baffled, but something is clearly not operating correctly.

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 pletely baffled, but something is clearly not operating correctly.

Share Improve this question asked Feb 24, 2013 at 22:48 tufelkindertufelkinder 1,2561 gold badge17 silver badges39 bronze badges 2
  • 4 Are you using jQuery 1.8 or later? addBack wasn't added until then. – cdmckay Commented Feb 24, 2013 at 22:51
  • I added it as an answer. – cdmckay Commented Feb 25, 2013 at 2:03
Add a ment  | 

1 Answer 1

Reset to default 12

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

发布评论

评论列表(0)

  1. 暂无评论