jstree remove default elements from context menu

前端 未结 4 2105
独厮守ぢ
独厮守ぢ 2021-02-07 07:12

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 th

相关标签:
4条回答
  • 2021-02-07 07:20

    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 extend the defaults, so this is a feature. Unfortunately the documentation currently lacks the detail on this point.

    0 讨论(0)
  • 2021-02-07 07:31

    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.

    0 讨论(0)
  • 2021-02-07 07:36

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

    contextmenu : {
        items : {
            "ccp" : false
        }
    }
    
    0 讨论(0)
  • 2021-02-07 07:45


    Set ccp, create, rename, remove to false like this :

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题