如何禁用单个菜单项?

How to disable a single menu item?

显然我还有另一个 Webix 问题。

我正在尝试禁用单个菜单项,但子菜单的 onItemClick 操作仍然有效。这是我的代码:

webix.ui({
  view:"menu", 
  id:'menu', 
  data:[
    { 
      id:'root',
      value:'Available actions',    
      config:{ 
        on: { 
          onItemClick: function(id){ webix.message(id) }
        }
      },
      submenu:[
       { id:'1', value:'Open...' }
     ]
    }
  ]
});

$$('menu').disableItem('1');

完整样本:http://webix.com/snippet/9128f7b0

我哪里错了,有什么方法可以禁用菜单项吗?

onItemClick 更改为 onMenuItemClick

示例:http://webix.com/snippet/8cba874c

来自Webix docs

Both methods can be used in either of menu inner events, for instance, click events: onMenuItemClick - fires on clicking all menu items regardless of hierarchy level. Ignores disabled items; onItemClick - standard event that fires on clicking any item of the same hierarchy level. Fires for disabled item as well.

console.log($$('menu').disableItem)

在此处记录

function (t) {this.getMenu(t).addCss(t,"webix_disabled");}

console.log($$('menu').getMenu)

在此处记录

function (t) {if(this.data.pull[t])return this;for(var e in this.data.pull){var i=this.getItem(e);if(i.submenu){var s=this.br(i).getMenu(t);if(s)return s}}}

$$('menu').disableItem('1');   // only add disabled class for id=1

您可以过滤 id === '1' onclick

onItemClick: function(id){ if(id !== '1'){// code here}}

或更改 onItemClick 2 onMenuItemClick

follow the #1 answer