在JsTree的CCP上下文菜单中禁用复制

时间:2014-10-28 20:54:10

标签: jstree

如何禁用"复制" (但不能剪切/粘贴)jsTree右键单击上下文菜单的功能?

4 个答案:

答案 0 :(得分:1)

这几乎可以解决问题。

 $("#housingTree").jstree({
            "plugins": ["themes", "html_data", "ui", "crrm", "hotkeys", "contextmenu"],

            "core": { "initially_open": ["phtml_1"] },


            "contextmenu": {
                "items": function ($node) {

                    return {
                        "Rename": {
                            "label": "Rename",
                            "action": function (obj) { this.rename(obj); }
                        },
                        "Create": {
                            "label": "Create",
                            "action": function (obj) { this.create(obj); }
                        },
                        "Delete": {
                            "label": "Delete",
                            "action": function (obj) { this.remove(obj); }
                        },
                        "Cut": {
                            "label": "Cut",
                            "action": function (obj) { this.cut(obj); }
                        },
                        "Paste": {
                            "label": "Paste",
                            "action": function (obj) { this.paste(obj); }
                        }
                    };
                }
            }
        })

答案 1 :(得分:1)

我不知道动作功能是默认功能还是自定义功能,但这对我没有用...无论如何你的帖子确实让我走上了正确的道路!谢谢!

这是我在找到另一篇文章后的方式:

"contextmenu": {
        "items": function ($node) {
            var tree = $("#html1Tree").jstree(true);
            return {
                "Rename": {
                    "label": "Rename",
                    "action": function (obj) { 
                        tree.edit($node);
                    }
                },
                "Create": {
                    "label": "Create",
                    "action": function (obj) { 
                        $node = tree.create_node($node);
                        tree.edit($node); 
                    }
                }
            };
        }
    }

jsTree and Context Menu: modify items

答案 2 :(得分:1)

较短的方法可能是

"contextmenu": {
   "items": function(node) {
           var defaultItems = $.jstree.defaults.contextmenu.items();
           console.log("default items : "+JSON.stringify(defaultItems));
          delete defaultItems.ccp.submenu.copy;
           return defaultItems;
        }
    },

您可以使用console.log(defaultItems)。它将打印对象的json表示。您也可以修改其他属性。

答案 3 :(得分:0)

这是我最简单的选择。 所有主要代码都放在“ contextmenu.items”块中。

$('#c-list').jstree({
        "core": {
            "themes": {"responsive": false},
            "check_callback": true,
        },
        "types": {
            "default": {
                "icon": "fa fa-folder text-warning fa-lg"
            },
            "file": {
                "icon": "fa fa-file text-warning fa-lg"
            }
        },
        "contextmenu":{
            'items' : function(node) {
                var items = $.jstree.defaults.contextmenu.items();
                items.ccp = false;

                return items;
            }
        },
        "plugins": ["contextmenu", "dnd", "types", "search", "wholerow","checkbox"]
    });
相关问题