对于我的asp.net mvc 3应用程序,我正在使用
this plugin.但是我有一个问题,我想在创建菜单后启用或禁用某些菜单项,如:
<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",accesskey:"c u t"},copy: {name: "Copy",icon: "copy",accesskey:"c o p y"},paste: {name: "Paste",icon: "paste",accesskey:"p a s t e"},"delete": {name: "Delete",icon: "delete",accesskey:"d e l t"},sep1: "---------",quit: {name: "Quit",icon: "quit",accesskey:"q u i t"} }}); //not working $('.context-menu-one').contextMenu('commands[0].disabled','true'); }); </script>
不工作,任何想法?
解决方法
根据插件的
documentation,您可以指定要调用的函数,以确定是否禁用了菜单项.
因此,您可以让该函数关闭局部变量,并更新该变量以启用或禁用这些项.就像是:
$(function() { var itemsDisabled = {}; // Enable everything initially. $.contextMenu({ selector: ".context-menu-one",items: { // [...] cut: { name: "Cut",accesskey: "c u t",disabled: function(key,opt) { return !!itemsDisabled[key]; } } // [...] } }); // Disable the "Cut" menu item. itemsDisabled["cut"] = true; });