For my asp.net mvc 3 application I'm using this plugin. But I have a problem, I want to enable or disable some menu items, after I have created the menu, like:
<script type="text/javascript">
$(function(){
/**************************************************
* Menu 1
**************************************************/
$.contextMenu({selector: '.context-menu-one', items: {
edit: {name: "Edit", icon: "edit", callback: $.noop, accesskey:"e d i t"},
cut: {name: "Cut", icon: "cut", callback: $.noop, accesskey:"c u t"},
copy: {name: "Copy", icon: "copy", callback: $.noop, accesskey:"c o p y"},
paste: {name: "Paste", icon: "paste", callback: $.noop, accesskey:"p a s t e"},
"delete": {name: "Delete", icon: "delete", callback: $.noop, accesskey:"d e l t"},
sep1: "---------",
quit: {name: "Quit", icon: "quit", callback: $.noop, accesskey:"q u i t"}
}});
//not working
$('.context-menu-one').contextMenu('commands[0].disabled','true');
});
</script>
Not working, any Idea?
According to the plugin's documentation, you can specify a function to be called in order to determine if a menu item is disabled or not.
So, you can have that function close over a local variable, and update that variable in order to enable or disable the items. Something like:
$(function() {
var itemsDisabled = {}; // Enable everything initially.
$.contextMenu({
selector: ".context-menu-one",
items: {
// [...]
cut: {
name: "Cut",
icon: "cut",
callback: $.noop,
accesskey: "c u t",
disabled: function(key, opt) {
return !!itemsDisabled[key];
}
}
// [...]
}
});
// Disable the "Cut" menu item.
itemsDisabled["cut"] = true;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With