Disable certain checkboxes from Jstree

安稳与你 提交于 2020-01-01 13:11:22

问题


So I have a Checkbox Tree created with JsTree. What I want to do is to set all the checkboxes initially to disabled and then I have an Array that contains the ids of the li tags. by browsing the table I should enable the checkboxes that belong to the tag with the specific id. When checked the Tree should respect the same orders as the default one (when parent checked enabled children should be checked as well ... etc). How can I proceed ? Thanks in advance. PS: The JsTree Plugin is wonderful. However it lacks a lot of documentation.


回答1:


You should overwrite default behaviour of check_node and uncheck_node functions, and create own disabled node type.

The code:

$('#tree').jstree({
    'plugins' : ['themes', 'html_data', 'checkbox', 'types'],
    'checkbox' : {
      'two_state' : true // Nessesary to disable default checking childrens
    },
    "types" : {
      "types": {
        "disabled" : { // Defining new type 'disabled'
          "check_node" : false, 
          "uncheck_node" : false 
        }, 
        "default" : { // Override default functionality
          "check_node" : function (node) {
            $(node).children('ul').children('li').children('a').children('.jstree-checkbox').click();
            return true;
          },
          "uncheck_node" : function (node) {
            $(node).children('ul').children('li').children('a').children('.jstree-checkbox').click();
            return true;
          }
        } 
      }
    }
});

Now to disable a node, add attribute rel="disabled" to their li tag.

Here is an example on JSFiddle.



来源:https://stackoverflow.com/questions/15784999/disable-certain-checkboxes-from-jstree

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