我正在使用 fancytree 来显示一个简单的树视图。树中有两种“节点类型”:组(可以有子节点)和项目(不能有子节点)。我正在尝试使用 contextMenu 扩展来添加功能。我的菜单上有三个选项:添加、编辑和删除。是否可以只显示“组”节点的“添加”菜单选项(它们的key
值以“g”开头)而不是“项目”节点?或者至少为“项目”节点禁用它?
var treeData = [{title: "All Locations", key: "g0", folder: true, expanded: true, children: [
{title: "Location 1", key: "g1", folder: true, children: [
{title: "Item 1", key: "81"},
{title: "Item 2", key: "82"},
{title: "Item 3", key: "83"},
]},
{title: "Location 2", key: "g2", folder: true, children: [
{title: "Item 4", key: "87"},
]},
{title: "Location 3", key: "g3", folder: true, expanded: true, children: [
{title: "Item 5", key: "88"},
{title: "Item 6", key: "89"},
]}
]}
];
$(function(){
// Create the tree inside the <div id="tree"> element.
$("#tree").fancytree({
checkbox: true,
debugLevel: 2,
selectMode: 3,
extensions: ['contextMenu'],
source: treeData,
contextMenu: {
menu: {
"add": { "name": "Add", "icon": "add" },
"edit": { "name": "Edit", "icon": "edit" },
"delete": { "name": "Delete", "icon": "delete" },
},
actions: function(node, action, options) {
alert('Selected action "' + action + '" on node ' + node.key);
}
}