1

我有一个带有复选框的 jsTree,它显示得很好。我可以打开和关闭节点,选中和取消选中复选框等。

当我尝试获取所有已检查的节点时,问题就出现了。下面我列出了我尝试过的所有方法,以及我尝试每种方法时收到的错误消息。

$.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

第二个($.jstree.plugin.checkbox)似乎最接近工作,但它似乎不喜欢“复选框”引用。它应该是 check_box 还是不同的东西?

这是我用来初始化树的代码:

$.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 };
            },
            plugins : [ "themes", "json_data", "ui", "checkbox"]
        }); 
    });
4

4 回答 4

3

我正在使用此代码在提交表单之前获取复选框:

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");
    });
});
于 2010-12-17T17:15:28.107 回答
1

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

于 2011-09-05T21:01:51.410 回答
0

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

于 2010-10-28T02:39:28.723 回答
0

你可以:

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

});

如果您只想要选定的节点,您可以拥有:

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

希望能帮助到你

于 2012-09-21T16:15:45.653 回答