开发者

jsTree checkbox plugin error

I have a jsTree with checkboxes that shows up just fine. I can open and close the nodes, check and uncheck the checkboxes, etc.

The problem comes in when I try to get all the nodes that have been checked. Below I list all the ways I have tried, along with the error messages I get when I try each one.

$.tree.plugin.checkbox.get_checked($.tree.reference("#smuDomains"));
$.tree is undefined

$.jstree.plugin.checkbox.get_checked($.jstree.reference("#smuDomains"));
$.jstree.plugin.checkbox is undefined

$.tree.plugins.checkbox.get_checked($.tree.reference("#smuDomains"));
$.tree is undefined

$.jstree.plugins.checkbox.get_checked($.jstree.reference("#smuDomains"));
$.jstree.plugins is undefined

The second one ($.jstree.plugin.checkbox) seems to be getting the closest to working, but it doesn't seem to like the "checkbox" reference. Should it be check_box or something different?

This is the code I use to init the tree:

$.jstree._themes = "../script/css/jstree/themes/";
$("#smuDomains").jstree({
    core : {}, 
    themes : {
        theme : "classic",
        dots : true,
        icons : true, 
        url : false
    },  
    json_data : {
        ajax : {
            url : "[the url]",
            datatype : "json",
            data : function(n) {
                return { id : n.attr ? n.attr("id") : 0 };
            },
            pl开发者_开发知识库ugins : [ "themes", "json_data", "ui", "checkbox"]
        }); 
    });


I'm using this code to get checked boxes just before submit the form :

jQuery('#myForm').submit(function() {
    jQuery('#mytree .jstree-checked').each(function () {
        var node = jQuery(this);
        var id = node.attr('id');
        var node_parent = node.parents('li:eq(0)');
        var pid = node_parent.attr('id');

        jQuery("<input>").attr("type", "hidden").attr("name", "treenode").val(id).appendTo("#mytree");
    });
});


$('#tree').jstree('get_checked')


one of the issues with get_checked is that it will stop at parent nodes that are checked.

We ended up going with something like this:

$('#idOfDivContainingTree .jstree-checked')

There is a risk of this not working with future versions of jsTree as it is dependent on the implementation


You can:

checked_nodes = $("#smuDomains").jstree("get_checked", null, true);

$.each(checked_nodes, function(k, n) {

node = $(n);
alert("name: "+node.attr("name")); //show each one of the nodes names

});

if you want just the selected nodes, you can have:

selected_nodes = $("#smuDomains").jstree("get_selected", null, true);

hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜