jtree中不同的树视图图标和启用/禁用复选框

different tree view icons and enable/disable checkboxes in jstree

本文关键字:启用 复选框 图标 视图 jtree      更新时间:2023-09-26

我需要改变树视图图标和启用/禁用复选框
请查看下面的代码:

function LoadJSTree() {
        $.noConflict();
        $(function () {
            $('#demoTree').jstree({
                'checkbox': {
                    'keep_selected_style': false,
                    'two_state': true
                },
                "types": {
                    "#": {
                        "max_children": 1,
                        "max_depth": 4,
                        "valid_children": ["root"]
                    },
                    "root": {
                        "icon": "/static/3.1.1/assets/images/tree_icon.png",
                        "valid_children": ["default"],
                        "check_node": false,
                    },
                    "default": {
                        "valid_children": ["default", "file"],
                        "check_node": true,
                        "uncheck_node": true
                    },
                    "disabled":{
                        "check_node": false,
                        "uncheck_node": false
                    },
                    "file": {
                        "icon": "glyphicon glyphicon-file",
                        "valid_children": [],
                        "check_node": true,
                        "uncheck_node": true
                    }
                },
                "plugins": ["types"],
                'core': {
                    'data': [
                        {
                            "text": "Root node", "type": "root", "parent":"#", "children": [
                                  { "text": "Child node 1", "type": "default" },
                                  { "text": "Child node 2", "type": "default" },
                                  { "text": "Child node 3", "type": "default" },
                                  { "text": "Child node 4", "type": "default" },
                                  { "text": "Child node 5", "type": "default" },
                                  { "text": "Child node 6", "type": "default" },
                                  { "text": "Child node 7", "type": "default" },
                                  { "text": "Child node 8", "type": "default" }
                            ]
                        }
                    ],
                },
                'plugins': ["checkbox"]
            });

它似乎不工作。

树显示使用相同的文件夹图标为每个节点和复选框总是为每个节点,它不应该禁用"根"节点?你能告诉我出了什么问题吗?

您在配置中列出了plugins两次:

"plugins": ["types"],
...
'plugins': ["checkbox"]

将其更改为单个条目:

"plugins": ["checkbox", "types"]

但是请记住,没有选项(在v.3中,如果您使用的是这个版本)可以根据节点的类型阻止操作。但是使用最新的jtree提交,你可以使用节点的state属性在每个节点上禁用复选框(你也可以禁用整个节点)——如果你需要的话,请看这里:
禁用某些复选框