jsTree 复选框插件错误

发布于 2024-09-28 09:45:36 字数 1187 浏览 8 评论 0原文

我有一个带有复选框的 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"]
        }); 
    });

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

原谅我要高飞 2024-10-05 09:45:36

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

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");
    });
});

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");
    });
});
紫瑟鸿黎 2024-10-05 09:45:36

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

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

原来是傀儡 2024-10-05 09:45:36

get_checked 的问题之一是它会在检查的父节点处停止。

我们最终采用了这样的方法:

$('#idOfDivContainingTree .jstree-checked')

这存在不适用于 jsTree 的未来版本的风险,因为它依赖于实现

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

苍白女子 2024-10-05 09:45:36

您可以:

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);

希望有帮助

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文