添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a extjs button "Order" with menu items 'orderInsuranceMenu' for the button. I need to hide the menu items depeniding on some condition. How can i achive it

orderInsuranceMenu = {
    id: 'menu-order-insurance'
    ,items: [
            id:'btnMenu1',
            text: 'Test Buton1',
            iconCls: 'icon-cls',
            listeners: {
                click: function(b,e){  
                   //some code goes here
            id:'btnMenu2',
            text: 'Test Buton2',
            iconCls: 'icon-first-title',
            listeners: {
                click: function(b,e){  
                    //Some code here
Order = new Ext.Button({
    text: 'Order '
    , iconCls: 'icon-go'
    , disabled: true
    , menu: orderInsuranceMenu
    , handler: function() {

I have tried this code but it doesnt work:

Ext.getCmp('btnMenu2').hide();

You can achieve this with the method setDisabled for the button. I.e:

Ext.getCmp('btnMenu2').setDisabled(true);

If you want to apply this for all items in your menu you can do this:

Ext.getCmp('menu-order-insurance').items.each(function(item) {
    if (item.isXType('button')) {
        item.setDisabled(true); // your condition here
                I Actualay want to hide the button.I tried to diable by using the above code even then its not working.
– Jemin
                Jun 13, 2011 at 15:06
                To hide something you can use the method .setVisible([bool]) for the button. However I'm unsure how you create the menu in the above example. What is 'extManager'? And where are you running the logic to set the button visible? Have it been created at the moment you try to access it etc?
– Torbjörn Hansson
                Jun 13, 2011 at 16:33
                extManager is the namespace used in our project.  Actually i have removed the extmanager while declaring and forgot to remove at menu.  Consider it as menu: orderInsuranceMenu.   The code is able to dislay the Button with menu items.  But i am unable to hide the menu items.  As you have given setVisible/setDisable function is not available in extmanager 2.2.  Here is the API link senchaexperts.com/api/extjs2.2  Can you please provide any other soloution to hide the menu items would be very helpfull
– Jemin
                Jun 13, 2011 at 22:51

In Extjs 2.2 there is no method to show or hide menu item by using isVisible So after lot of digging and checking in firebug the final soloution I found was to hide or show the specific item as shown below

extManager.orderInsuranceMenu.items.items[1].hide();
orderInsuranceMenu.items.items[1].show();

You can use the setVisible method available in 2.2, in menu items. http://i.stack.imgur.com/kdw7f.png

If for some reason that does not work, I would resort to removing the item from the menu, and then adding it back into the menu when it is needed.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.