本文介绍了Jstree-预检查复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用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
,默认情况下会预先选中该框
解决方案
请确保添加"checked"类,因为该类用于在load =时预先选中复选框.
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
解决方案
Make sure to add the "checked" class because it used to pre-check boxes on load =)
这篇关于Jstree-预检查复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!