Having a jsTree with checkboxes, how can i disable all checkboxes?

六月ゝ 毕业季﹏ 提交于 2019-12-12 11:28:18

问题


I have a jsTree, built dynamically, that allows the user to select whatever nodes he chooses.

Now i'm trying to make this tree readonly so that other users can see the information without altering it.

All examples i find are about disabling a specific node...

My question is: Is there a way to define all the checkboxes on the tree to readonly?

Code being used:

jQuery.noConflict();
jQuery(
    function() {
        jQuery("#divTree").jstree(
            {
                "plugins": ["themes", "json_data", "checkbox", "sort", "ui", "real_checkboxes"],
                json_data: { data: data }
            }
        );
    }
);

回答1:


Problem Solved. Here is the solution for anyone that needs it.

jQuery.noConflict();
jQuery(
    function() {
        jQuery("#divTree")
        <% if(isReadOnly) { %>
        .bind("loaded.jstree", function (event, data) 
             {
            jQuery('.jstree a').click(function() {return false;});
        })
        <% } %>
       .jstree(
                {
                    "plugins": ["themes", "json_data", "checkbox", "sort", "ui", "real_checkboxes"],
                    json_data: { data: data }
                }
            );
        }
    );



回答2:


You can define this in your default type, or define your own type for specific nodes then bind them to it:

jQuery("#divTree").jstree({
    "types": {
        "default": {
            "check_node": false,
            "uncheck_node": false
        }
    },    
    "plugins": ["themes", "json_data", "checkbox", "sort", "ui", "real_checkboxes"],
    "json_data": { data: data }
});

If I were you, I'd just wrap that types declaration inside a server side if statement to determine whether you want this tree to be read only or not.

Docs: http://www.jstree.com/documentation/types



来源:https://stackoverflow.com/questions/20491989/having-a-jstree-with-checkboxes-how-can-i-disable-all-checkboxes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!