jsTree 隐藏复选框
我正在使用 jsTree jQuery 插件来显示 5 层深的树。我不想在最后一级显示复选框。有什么办法可以在设置中做到这一点,或者事后我可以做一些 jquery 处理来删除这些复选框吗?我可以使用它们类型插件禁用它们,但我真的希望它们不可见。
这是我的树的示例“[x]”=一个复选框
[x] lvl 1
[x] lvl 2
[x] lvl 3
[x] lvl 4
[x] lvl 5a
[x] lvl 5b
[x] lvl 5c
这是我想要的示例“[x]”=一个复选框
[x] lvl 1
[x] lvl 2
[x] lvl 3
[x] lvl 4
lvl 5a
lvl 5b
lvl 5c
编辑找到答案
找到了答案。添加加载树时将调用的 .bind,然后添加一些简单的 jquery 来隐藏复选框。
$("#right-tree2").bind("loaded.jstree", function(event, data) {
$('.lvl4').find('ins.jstree-checkbox').hide();
})
.jstree({....});
I am using the jsTree jQuery plugin to display a 5 level deep tree. I would like to not show checkboxes on the last level. Is there any way to do that in the setting or some jquery processing I can do afterwards to remove those checkboxes? I am able to disable them using they types plugin, but I really want them to not be visible.
Here is an exmple of my tree "[x]" = a checkbox
[x] lvl 1
[x] lvl 2
[x] lvl 3
[x] lvl 4
[x] lvl 5a
[x] lvl 5b
[x] lvl 5c
Here is an exmple of what I want "[x]" = a checkbox
[x] lvl 1
[x] lvl 2
[x] lvl 3
[x] lvl 4
lvl 5a
lvl 5b
lvl 5c
EDIT ANSWER FOUND
Found the answer. Add the .bind that will get called when the tree is loaded then some simple jquery to hide the checkbox.
$("#right-tree2").bind("loaded.jstree", function(event, data) {
$('.lvl4').find('ins.jstree-checkbox').hide();
})
.jstree({....});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您从 JSON 创建树,那么我发现删除节点的最简单方法是使用一些 css。
在实际的 JSON 中,将要禁用的节点的 a_attr 字段设置为“no_checkbox”,如下所示。这会将“no_checkbox”类添加到包含节点文本、图标和复选框的
元素。
在 css 中,创建一个如下选择器:
完成!
这只会选择直接位于具有
no_checkbox
类的元素内部的复选框,并将它们从布局中删除。与其他答案相比,此方法的优点是您只需从
元素中删除类
no_checkbox
即可恢复复选框。例如,您可以在select_node.jstree
事件的事件处理程序中执行此操作,然后获取作为参数传入的 DOM 节点。当然,如果您使用 HTML 而不是 JSON 输入数据,您可以手动将 css 类添加到 html 中,或者使用 php/其他服务器端语言,它的工作原理是一样的。
If you're creating the tree from JSON, then I've found the easiest way to remove the nodes is using some css.
In the actual JSON, set the a_attr field of the nodes you want to be disabled to "no_checkbox" as below. This will add the class "no_checkbox" to the
<a>
element that contains the node text, icons and checkboxes.In the css, create a selector like this:
Done!
This will only select checkboxes that are directly inside the
<a>
element with theno_checkbox
class, and it will remove them from the layout. The advantage of this method over the other answers is that you can bring back the checkbox just by removing the classno_checkbox
from the<a>
element. For example you can do this in the event handlers for theselect_node.jstree
event, and then get the DOM node that's passed in as an argument.Of course if you're inputting data using HTML instead of JSON, you can just add the css class into the html manually, or using php/other server side language, and it will work just the same.
要完全隐藏特定节点的复选框(假设该节点数据来自服务器),请添加以下 JS 代码
并在 CSS 中添加以下样式
它将完全隐藏提供的节点 ID 中的复选框,这对我来说就像一个魅力。 感谢此链接。
To completely hide checkbox from the specific node giving that node data is coming from server, add following JS code
and in CSS, add the following style
It will completely hide checkbox from provided node id, this worked like a charm for me. Thanks to this link.
您还可以阻止复选框插件添加它们:
将一个类添加到您不希望有复选框的任何节点类型的
标记中(我使用的与my rel)。
编辑jquery.jstree.js复选框插件,将类添加到 .not() 语句,其中复选框将添加到 DOM。在 1.0-rc3 中,它看起来像这样(大约第 2870 行):
这样,您不必添加然后删除它们(如果可以避免的话,这是不好的做法)。
You can also prevent the checkbox plugin from adding them:
Add a class to the
<a>
tag of any node type that you do not want to have a checkbox (I used the same as my rel).Edit jquery.jstree.js Checkbox plugin to add the classes to the .not() statement where the checkboxes are added to the DOM. In 1.0-rc3 it looks like this (around line 2870):
This way, you don't have to add, then remove them (bad practice if it can be avoided).
试试这个,
try this,
我找到了另一个使用 css 的解决方案。这个简单的代码隐藏了第一层中的复选框
I found another solution using css. This simple code hides the checkbox in the first layer
我在 @Migwell 的答案中添加了我自己的开发,其中我使用了“Types”jstree 插件。
对于 OP 的用例,他可以简单地向每个级别添加一种类型,或者仅向最后一个级别添加一个类型,以最简单的为准。他不想要复选框的级别将类添加到其 a_attr 中。 Types 插件的 a_attr 接受一个对象。
I added onto @Migwell's answer for my own development in which I used the 'Types' jstree plugin.
For OP's use case, he could simply add a type to each level, or just one to the last level, whichever is easiest. The level he does not want checkboxes gets the class added to its a_attr's. The Types plugin's a_attr accepts an object.