简体   繁体   English

jstree禁用复选框

[英]jstree disable checkbox

I am currently working on some POC using JS Tree plugin and related check box plugin. 我目前正在使用JS Tree插件和相关的复选框插件来处理一些POC。 For certain nodes I need to check the check box by default and disable any further selection.I found the function to hide the check box 对于某些节点,我需要在默认情况下选中复选框并禁用任何进一步的选择。我找到了隐藏复选框的功能

.bind("load_node.jstree", function (e, data) {
          $(this).find('li[rel!=file]').find('.jstree-checkbox:first').hide();
      });

instead of hiding the check box completely I want to find a way to disable check box for certain nodes 而不是完全隐藏复选框我想找到一种方法来禁用某些节点的复选框

You will need to define a "disabled" type (using the types plugin) and then assign that type to the desired node. 您需要定义“禁用”类型(使用类型插件),然后将该类型分配给所需的节点。

Take for instance this "disabled" type definition: 以这种“禁用”类型定义为例:

           "types" : {
                "types": {
                "disabled" : { 
                      "check_node" : false, 
                      "uncheck_node" : false 
                    } 
                }
            }

and the type assigment: 和类型分配:

$.jstree._reference('#tree').set_type("disabled", "#node5");

More info on the types plugin can be found here and you can also check this google group with more info on disabling checkboxes 有关类型插件的更多信息可以在此处找到,您还可以查看此google组,其中包含有关禁用复选框的详细信息

Hope it helps! 希望能帮助到你!

Thank you to mcabral and Tomasz for their answer. 感谢mcabral和Tomasz的回答。 It helped me to achieve the right result. 它帮助我取得了正确的结果。 However, I needed to add some extra lines in order to get it working properly. 但是,我需要添加一些额外的行以使其正常工作。 Here is what I did: 这是我做的:

You need to add two attributes to the <li> tag wich are the rel='disable' to indicate jstree that this will be the new type for the checkbox, instead of default and the class='jstree-checked' attribute which will pre-check the checkboxes when loading the tree. 您需要向<li>标记添加两个属性,即rel='disable'以指示jstree这将是复选框的新类型,而不是默认值和class='jstree-checked'属性 - 加载树时选中复选框。

$rel = ( 'if the checkbox need to be pre-checked' )? 'rel="disabled" class="jstree-checked"' : '';
            echo '<li id="checkbox_id" '. $rel .'>';

Then based on the previous answer you need to define the 'disable' type that was used in the rel attribute as follows: 然后根据前面的答案,您需要定义rel属性中使用的'disable'类型,如下所示:

.jstree({
                    "types" : 
                    {
                        "types" : {
                            "disabled" : {
                                 "check_node" : false, 
                                 "uncheck_node" : false 
                            }
                        }
                    },
        "plugins" : ["themes","html_data","ui","crrm","types", "checkbox"],
                    "checkbox" : { "two_state" : true },
    })

If your item is static; 如果你的物品是静止的; for example.... always there like in my scenario. 例如....总是那样在我的场景中。

I just simply hid the checkbox on that item with CSS. 我只是简单地用CSS隐藏了该项目的复选框。 As I do server side checking, any malicious attempt at altering it will be discarded anyway. 当我进行服务器端检查时,无论如何都会丢弃任何改变它的恶意企图。

#my_item_id .jstree-checkbox {
    display: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM