问题
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