【发布时间】:2020-03-07 16:53:17
【问题描述】:
下面的代码显示了我尝试仅在级别 1 显示 jstree 上下文菜单。
菜单显示在第一级,选择菜单项会显示警报。 菜单不显示在第 2 级,这很好,我想要什么。
但是,在选择了一个 2 级节点之后,然后选择了一个 1 级节点,菜单会按原样显示,但选择菜单项没有任何作用。
任何帮助表示赞赏。
小提琴:https://jsfiddle.net/NervousElk/4p5hqg0r/17/小提琴
document.getElementById("gobtn").addEventListener("click", buildtree);
function buildtree()
{
$('#ttstafftree').jstree(
{
plugins: ["wholerow", "json_data", "ui", "themes", "sort", "state", "contextmenu"],
'core' :
{
"check_callback": true,
'data' :
[
{ "id" : "ajson1", "parent" : "#", "text" : "Root 1" },
{ "id" : "ajson1-1", "parent" : "ajson1", "text" : "a" },
{ "id" : "ajson2", "parent" : "#", "text" : "Root 2" },
{ "id" : "ajson2-1", "parent" : "ajson2", "text" : "b" },
]
},
"contextmenu":
{
"items":
{
opt1:
{
label: "opt 1",
action: function(data)
{
alert('opt 1')
}
},
opt2:
{
label: "opt 2",
action: function(data)
{
alert('opt 2')
}
}
}
},
})
.on('show_contextmenu.jstree', function(e, reference, element)
{
if ( reference.node.parents.length != 1)
{
$('.vakata-context').remove();
}
});
}
【问题讨论】:
标签: conditional-statements contextmenu jstree