禁用Jstree中的某些复选框 [英] Disable certain checkboxes from Jstree

查看:262
本文介绍了禁用Jstree中的某些复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个用JsTree创建的复选框树.我想要做的是首先将所有复选框设置为禁用,然后我有一个包含li标签ID的数组.通过浏览表格,我应该启用属于具有特定ID的标签的复选框.选中时,树应遵循与默认顺序相同的顺序(当父级被选中时,启用子级也应被选中...等等).我该如何进行?提前致谢. PS:JsTree插件很棒.但是,它缺少很多文档.

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.

推荐答案

您应该覆盖check_nodeuncheck_node函数的默认行为,并创建自己的禁用节点类型.

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

代码:

$('#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;
          }
        } 
      }
    }
});

现在要禁用节点,请将属性rel="disabled"添加到其li标记中.

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

这是JSFiddle上的一个示例.

这篇关于禁用Jstree中的某些复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆