如何以编程方式隐藏TabPanel中的Tab(ExtJS 3)

如何以编程方式隐藏TabPanel中的Tab(ExtJS 3)

问题描述:

我的TabPanel代码:

This my TabPanel code:

在代码中有两个选项卡(tab1和tab2)在TabPanel(tabs_panel)中

inside the code there is two tabs (tab1 and tab2) in the TabPanel (tabs_panel)

MyTabPanelUi = Ext.extend(Ext.TabPanel, {
    activeTab: 0,
    height: 210,
    resizeTabs: true,
    tabWidth: 266,
    id: 'tabs_panel',
    initComponent: function () {
        this.items = [{
            xtype: 'panel',
            title: 'Project',
            padding: 20,
            height: 150,
            id: 'tab1'
        }, {
            xtype: 'panel',
            title: 'Service',
            height: 150,
            padding: 20,
            id: 'tab2'
        }]
    }
});

我试图隐藏tab2使用下面的代码,但这个下面的代码

I'm trying to hide tab2 using bellow code but this bellow code

var tabPanel = Ext.getCmp('tabs_panel');
var tabToHide = Ext.getCmp('tab2');
tabPanel.hideTabStripItem(tabToHide);

但不知何故,上面的代码对我来说不起作用。如何解决问题?

but somehow this above code does not work for me. How can I fix the problem?

您有两种可能:

var tabPanel = Ext.getCmp('tabs_panel');
tabPanel.hideTabStripItem("tab2"); // with tab id

var tabPanel = Ext.getCmp('tabs_panel');
tabPanel.hideTabStripItem(1); // with tab index