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
,默认情况下这将预先选中该框
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保添加“checked”类,因为它用于在加载时预先检查框 =)
Make sure to add the "checked" class because it used to pre-check boxes on load =)
以下代码可能会解决您的问题。
The following code may resolve your issue.
解决方案是添加类“jstree-checked”,这将默认预先选中该框
Solution is to add the class 'jstree-checked', this will by default pre-check the box