javascript jstree 从上下文菜单中删除默认元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8491526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 03:37:02  来源:igfitidea点击:

jstree remove default elements from context menu

javascripthtmljstree

提问by LostMohican

I have a problem with JsTree's contextmenu, how can I remove the default elements from the contextmenu like Create, Delete, Rename? I want to provide elements of my own, but the default elements are still at the contextmenu.

我对 JsTree 的上下文菜单有问题,如何从上下文菜单中删除默认元素,如创建、删除、重命名?我想提供我自己的元素,但默认元素仍在上下文菜单中。

    "contextmenu" : {
                    "items" : {
                        "IsimVer" : {
                            "label" : "?sim De?i?tir",
                            "action" : function (obj) { this.rename(obj); }
                        },
                        "Ekle" : {
                            "label" : "Ekle",
                            "action" : function (obj) { this.create(obj); }
                        },
                        "Sil" : {
                            "label" : "Sil",
                            "action" : function (obj) { this.remove(obj); }
                        }
}

采纳答案by contrebis

I had this issue a couple of days ago but haven't yet decided if this is a bug or a feature. It may be related to the order in which the plugins are loaded.

几天前我遇到了这个问题,但尚未确定这是错误还是功能。这可能与插件加载的顺序有关。

What worked for me was returning the items from a function:

对我有用的是从函数返回项目:

"contextmenu" : {
    "items" : function ($node) {
        return {
            "IsimVer" : {
                "label" : "?sim De?i?tir",
                "action" : function (obj) { this.rename(obj); }
            },
            "Ekle" : {
                "label" : "Ekle",
                "action" : function (obj) { this.create(obj); }
            },
            "Sil" : {
                "label" : "Sil",
                "action" : function (obj) { this.remove(obj); }
            }
        };
    }
}

After some searching it seems that the default behaviour is for your menu items to extendthe defaults, so this is a feature. Unfortunately the documentation currently lacks the detail on this point.

经过一番搜索,似乎默认行为是您的菜单项扩展默认值,所以这是一个功能。不幸的是,文档目前缺乏关于这一点的详细信息。

回答by Gorky

If you like to modify labels of existing items or remove a few, a simple solution like below will work

如果您想修改现有项目的标签或删除一些标签,如下所示的简单解决方案将起作用

"contextmenu": {
   "items": function(node) {
           var defaultItems = $.jstree.defaults.contextmenu.items();
           defaultItems.create.label = "Ekle";
           delete defaultItems.ccp;
           return defaultItems;
        }
    }

This will set "Create" items label as "Ekle" and remove cut copy paste from default items.

这会将“创建”项目标签设置为“Ekle”并从默认项目中删除剪切复制粘贴。

回答by user570605

Just set value to false in items object. For example, to disable edit (cut, copy, paste) menu try this:

只需在 items 对象中将值设置为 false 即可。例如,要禁用编辑(剪切、复制、粘贴)菜单,试试这个:

contextmenu : {
    items : {
        "ccp" : false
    }
}

回答by Ronny Susetyo


Set ccp, create, rename, removeto falselike this :


ccpcreaterenameremove 设置false ,如下所示:

plugins : ["themes","json_data","ui","crrm", "hotkeys", "types", "contextmenu"],
contextmenu : {
    items : {
        "IsimVer" : {
            "label" : "IsimVer",
            "action" : function (obj) { alert("IsimVer"); }
        },
        "Ekle" : {
            "label" : "Ekle",
            "action" : function (obj) { alert("Ekle"); }
        },
        "Sil" : {
            "label" : "Sil",
            "action" : function (obj) { alert("tiga"); }
        },
        "ccp" : false,
        "create" : false,
        "rename" : false,
        "remove" : false
    }
}