首页 > 解决方案 > 在 jsTree 的上下文菜单中创建功能不起作用

问题描述

定义“类型”插件时不会创建新节点。

请看这个小提琴。我无法在树中创建新节点。 http://jsfiddle.net/z8L5r9w3/1/

$('#jstree').jstree({
"core" : {
    "check_callback" : true,
    "data" : [
        { "text" : "Branch 1", "type" : "branch", "children" : [
            { "text" : "leaf 1.1", "type" : "leaf" },
            { "text" : "leaf 1.2", "type" : "leaf" },
            { "text" : "leaf 1.3", "type" : "leaf" }
           ]
        },
        { "text" : "Branch 2", "type" : "branch", "children" : [
            { "text" : "leaf 2.1", "type" : "leaf" },
            { "text" : "leaf 2.2", "type" : "leaf" },
            { "text" : "leaf 2.3", "type" : "leaf" }
           ]
        }
    ]
},
        "types" : {
            "#" : {
                "valid_children" : ["branch"]
            },
            "branch" : {
                "valid_children" : ["leaf"]
            },
            "leaf" : {
                "valid_children" : []
            }
        },
"plugins" : ["types", "dnd", "contextmenu"]});

标签: javascriptjqueryjstreejstree-dndjstree-search

解决方案


您对“类型”有疑问。“上下文菜单”中的“创建”操作不知道“分支”和“叶子”的类型,并使用“类型”创建新节点:“默认”。你可以看到这个:

        "types" : {
            "#" : {
                "valid_children" : ["branch", "default"]
            },
            "branch" : {
                "valid_children" : ["leaf", "default"]
            },
            "leaf" : {
                "valid_children" : []
            }
        },

推荐阅读