Jstree - 预选中复选框

发布于 2024-12-06 16:28:46 字数 1482 浏览 8 评论 0原文

我正在使用 JsTree 1.0,并且在使用复选框插件预检查复选框时遇到问题。

这是我的完整代码:

 $(".tree").bind("loaded.jstree", function (event, data) {
                 $('.tree li.checked').each(function () {
                     $(this).prop("checked", true);
                })
            }).jstree({ 
                "core" : { "animation" : 0}, 
                "json_data" : {
                    "ajax" : {
                        "url" : "/admin/posts/get_taxonomy_tree",
                        "data" : function (n) { 
                            return { id : n.attr ? n.attr("id") : 0 }; 
                        }
                    },
                    "progressive_render" : true
                },
                "checkbox" : {
                    "real_checkboxes" : true,
                    "real_checkboxes_names" : function(n){
                        return [("term_taxonomy_id_" + (n[0].id || Math.ceil(Math.random() * 10000))), 1]; 
                    }
                    },
                "themes" : {
                    "url"   :   "/assets/admin/js/jstree/themes/default/style.css",
                    "icons": false
                },
                "plugins" : [ "themes", "json_data", "checkbox" ]
            }).delegate("a", "click", function (event, data) { event.preventDefault(); });

我已经为 loading.jstree 添加了绑定事件,但这不正确 - 不起作用。

有什么想法吗?谢谢你!

编辑:

解决方案是添加类 jstree-checked,默认情况下这将预先选中该框

I'm using JsTree 1.0 and having trouble pre-checking checkboxes using the checkbox plugin.

Here's my full code:

 $(".tree").bind("loaded.jstree", function (event, data) {
                 $('.tree li.checked').each(function () {
                     $(this).prop("checked", true);
                })
            }).jstree({ 
                "core" : { "animation" : 0}, 
                "json_data" : {
                    "ajax" : {
                        "url" : "/admin/posts/get_taxonomy_tree",
                        "data" : function (n) { 
                            return { id : n.attr ? n.attr("id") : 0 }; 
                        }
                    },
                    "progressive_render" : true
                },
                "checkbox" : {
                    "real_checkboxes" : true,
                    "real_checkboxes_names" : function(n){
                        return [("term_taxonomy_id_" + (n[0].id || Math.ceil(Math.random() * 10000))), 1]; 
                    }
                    },
                "themes" : {
                    "url"   :   "/assets/admin/js/jstree/themes/default/style.css",
                    "icons": false
                },
                "plugins" : [ "themes", "json_data", "checkbox" ]
            }).delegate("a", "click", function (event, data) { event.preventDefault(); });

I've added the bind event for loading.jstree, but this isn't correct - doesn't work.

Any ideas? Thank you!

EDIT:

Solution is to add the class jstree-checked, this will by default pre-check the box

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

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

发布评论

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

评论(3

半透明的墙 2024-12-13 16:28:47

确保添加“checked”类,因为它用于在加载时预先检查框 =)

Make sure to add the "checked" class because it used to pre-check boxes on load =)

江南烟雨〆相思醉 2024-12-13 16:28:47

以下代码可能会解决您的问题。

$('.tree').jstree("check_all");

The following code may resolve your issue.

$('.tree').jstree("check_all");
谜泪 2024-12-13 16:28:46

解决方案是添加类“jstree-checked”,这将默认预先选中该框

Solution is to add the class 'jstree-checked', this will by default pre-check the box

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