【问题标题】:EXT js Button menu item disableEXT js 按钮菜单项禁用
【发布时间】:2011-09-13 20:50:56
【问题描述】:

我有一个 extjs 按钮“订单”,该按钮带有菜单项“orderInsuranceMenu”。我需要在某些条件下隐藏菜单项。我怎样才能实现它

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() {
    }

});

我已经尝试过这段代码,但它不起作用:

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

【问题讨论】:

    标签: button extjs menu hide


    【解决方案1】:

    解决方案:

    在 Extjs 2.2 中没有使用 isVisible 显示或隐藏菜单项的方法 因此,经过大量挖掘和检查萤火虫后,我发现的最终解决方案是隐藏或显示特定项目,如下所示

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

    【讨论】:

      【解决方案2】:

      您可以在菜单项中使用 2.2 中可用的 setVisible 方法。 http://i.stack.imgur.com/kdw7f.png

      如果由于某种原因不起作用,我会从菜单中删除该项目,然后在需要时将其重新添加到菜单中。

      【讨论】:

        【解决方案3】:

        您可以使用按钮的setDisabled 方法实现此目的。即:

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

        如果您想将此应用于菜单中的所有项目,您可以这样做:

        Ext.getCmp('menu-order-insurance').items.each(function(item) {
            if (item.isXType('button')) {
                item.setDisabled(true); // your condition here
            }
        });
        

        【讨论】:

        • 我实际上想隐藏按钮。我尝试使用上面的代码进行禁用,即使它不起作用。
        • 我实际上使用的是 EXT 2.2
        • 要隐藏某些内容,您可以对按钮使用 .setVisible([bool]) 方法。但是我不确定您如何在上面的示例中创建菜单。什么是'extManager'?你在哪里运行设置按钮可见的逻辑?它是在您尝试访问它时创建的吗?
        • @Jemsworld 不要认为此代码在 2.2 和 4.0 之间有任何相关更改。
        • extManager 是我们项目中使用的命名空间。实际上,我在声明时删除了 extmanager 并忘记在菜单中删除。将其视为菜单:orderInsuranceMenu。该代码能够显示带有菜单项的按钮。但我无法隐藏菜单项。正如您给出的 setVisible/setDisable 函数在 extmanager 2.2 中不可用。这是 API 链接senchaexperts.com/api/extjs2.2 您能否提供任何其他解决方案来隐藏菜单项会非常有帮助
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多