温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在jstree中实现checkbox默认选中和隐藏

发布时间:2021-04-06 16:34:51 阅读:417 作者:Leah 栏目:web开发

怎么在jstree中实现checkbox默认选中和隐藏?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

首先需要配置 Checkbox plugin

"plugins" : ['checkbox']

设置默认选中状态(checkbox 选中)

state: {checkedtrue}
$.jstree.defaults.checkbox.tie_selection

示例:

$('#demo_tree').jstree({
 "core" : {
  'data': [
   { "id" "ajson1""parent" "#""text" "Simple root node", state: {checkedtrue}},
   { "id" "ajson2""parent" "#""text" "Root node 2" },
   { "id" "ajson3""parent" "ajson2""text" "Child 1" },
   { "id" "ajson4""parent" "ajson2""text" "Child 2" },
  ]
 },
 "plugins" : ['checkbox'],
 "checkbox" : {
  "tie_selection"false,
 }
});

jstree复选框自定义显示隐藏

jstree 本身不支持在节点中隐藏 checkbox,国外有个大佬给出一个利用 css 来隐藏的解决方案:

首先来一段 css

.no_checkbox>i.jstree-checkbox{display:none}

然后在 data 的 json 数据结构中

$('#demo_tree').jstree({
 "core" : {
  'data': [
   { "id" "ajson1""parent" "#""text" "Simple root node", state: {checkedtrue}},
   { "id" "ajson2""parent" "#""text" "Root node 2" },
   { "id" "ajson3""parent" "ajson2""text" "Child 1" , a_attr: {class"no_checkbox"}},
   { "id" "ajson4""parent" "ajson2""text" "Child 2" },
  ]
 },
 "plugins" : ['checkbox'],
});

效果:

jstree version => 3.3.8

看完上述内容,你们掌握怎么在jstree中实现checkbox默认选中和隐藏的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI