2016-12-07 60 views
2

我正在使用菜单为我的网格中的行显示多个选项。该菜单正确显示文本,我希望能够动态禁用其中一些选项。EXTJS 5 - 如何禁用菜单中的某些项目

这是我的菜单:

Ext.create('Ext.menu.Menu', { 
items: [{ 
    text: 'option 1' 
},{ 
    text: 'option 2' 
},{ 
    text: 'option 3' 
}] 
}); 

我试着给每个项目的ID和ID禁用它,但我在控制台得到一个错误说

Uncaught TypeError: Cannot read property 'contains' of undefined(…) 

有谁知道解决这个问题?

回答

0
var menu=Ext.create('Ext.menu.Menu', { 
items: [{ 
    text: 'option 1' 
},{ 
    text: 'option 2' 
},{ 
    text: 'option 3' 
}] 
}); 
var item=menu.getComponent(//index of the item) 
item.setDisabled(true); 
+1

这个工作满的例子。谢谢! –

1

您只需拨打menuitem上的方法disable即可。

var item = Ext.first('#mySpecialMenuItem'); 
item.disable(); 

事情是这样的:

{ 
    xtype: 'menu', 
    floating: false, 
    id: 'myMenu', 
    width: 120, 
    items: [ 
     { 
      xtype: 'menuitem', 
      id: 'mySpecialMenuItem', 
      text: 'Menu Item' 
     }, 
     { 
      xtype: 'menuitem', 
      text: 'Menu Item' 
     }, 
     { 
      xtype: 'menuitem', 
      text: 'Menu Item' 
     } 
    ] 
}, 
{ 
    xtype: 'button', 
    handler: function(button, e) { 
     // somehow get the item 
     var item = Ext.first('#mySpecialMenuItem'); 
     // call disable 
     item.disable(); 

    }, 
    text: 'Disable Item' 
} 

入住这拨弄 https://fiddle.sencha.com/#view/editor&fiddle/1m2q

相关问题