在jquery上下文菜单中显示事件不起作用

时间:2015-06-06 18:04:14

标签: jquery contextmenu

我希望在显示之前显示并隐藏上下文菜单的一些选项。所以我在documentation上使用show event提及。但这对我不起作用。 fiddle

show:function(){
        alert(0)
}

1 个答案:

答案 0 :(得分:1)

所有选项都只是javascript对象。所以在$(document).ready上你可以修改选项集合以满足你的需求。以下是我修改选项的示例:

$(function () {
    var menuItems = {};

    function somelogic() {
        alert('hi');
        return true;
    }

    if (somelogic()) {
        menuItems = {
            "edit": { name: "Edit", icon: "edit" },
            "cut": { name: "Cut", icon: "cut" },
            "copy": { name: "Copy This to the Clipboard Please", icon: "copy" },
            "paste": { name: "Paste", icon: "paste" },
            "delete": { name: "Delete", icon: "delete" },
            "submenu": {
                name: "Submenu",
                items: {
                    "submenu_item1": {
                        // NOTE: this is the item that wraps in IE9 but not in Firefox
                        name: "Change Reporting Interval"
                    },
                    "submenu_item2": {
                        name: "Item 2"
                    }
                }
            },
            "quit": { name: "Quit", icon: "quit" }
        }
    }



    $.contextMenu({
        selector: '.context-menu-one',
        callback: function (key, options) {
            var m = "clicked: " + key;
            window.console && console.log(m) || alert(m);
        },
        items: menuItems
    });
});