ContextMenu how to build menu conditionally
I'm new to contextMenu. I'm trying to build a simple example using the example code below.
My question is: how can I use JS code to conditionally allow or disallow a menu item?
For example, if I didn't want the Delete menu item based on a JS variable, how would I code that?
I tried adding an if statement in the menu but items: {} didn't like that.
Thank you...
- $(function(){ $.contextMenu({ selector: '.context-menu-one', trigger: 'left', callback: function(key, options) { var m = "clicked: " + key; window.console && console.log(m) || alert(m); }, items: { "edit": {name: "Edit", icon: "edit"}, "cut": {name: "Cut", icon: "cut"}, "copy": {name: "Copy", icon: "copy"}, "paste": {name: "Paste", icon: "paste"}, "delete": {name: "Delete", icon: "delete"}, "sep1": "---------", "quit": {name: "Quit", icon: function($element, key, item){ return 'context-menu-icon context-menu-icon-quit'; }} } }); });