Jstree - precheck checkboxes

旧巷老猫 提交于 2019-12-23 04:29:39

问题


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


回答1:


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




回答2:


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




回答3:


The following code may resolve your issue.

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


来源:https://stackoverflow.com/questions/7573859/jstree-precheck-checkboxes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!