简体   繁体   English

如何在选项卡开关中激活选项卡面板的第二项

[英]How to activate second item of tabpanel in tab switch

I have tab panel.我有标签面板。 On tab switch (2nd tab) some time I want to render at tab2panel1 and sometime at tab2panel2 based on some condition.在选项卡开关(第二个选项卡)上,有时我想根据某些条件在 tab2panel1 和有时在 tab2panel2 进行渲染。 here is my configuration.这是我的配置。

{
            "xtype" : "tabpanel",
            "tabPosition" : "left",
            "layout" : "fit",
            "tabRotation" : 0.0,
            "items" : [ 
                {
                    "xtype" : "panel",
                    "title" : "tab1",
                    "icon" : "classic/resources/images/Profile_active.png",
                    "layout" : "card",
                    "items" : [ 
                    {
                         "xtype" : "panel",
                        "title" : "tab1panel1",
                    }]
                }, 
                {
                    "xtype" : "panel",
                    "title" : "tab1",
                    "icon" : "classic/resources/images/Profile_active.png",
                    "layout" : "card",
                    "items" : [ 
                    {
                         "xtype" : "panel",
                        "title" : "tab2panel1",
                    },{
                         "xtype" : "panel",
                        "title" : "tab2panel1",
                    }]
                },  
            ]
        }

Here is what I am trying but it is changing to tab1.这是我正在尝试的,但它正在更改为 tab1。 not the panel item of tab 2.不是选项卡 2 的面板项目。

tabchange: function (tab, newTab, oldTab) {
        let _this = this,
            cardItems = newTab.items;
        
        if (tab.changeValue == true) {
             newTab.getLayout().setActiveItem(1);
        }
    }

But this leading to the tab of 1. not item inside the tab.但这导致了 1. 的选项卡,而不是选项卡内的项目。 Any help here.任何帮助在这里。

I think it is wrong place, better to listen tab activation event.我认为这是错误的地方,最好听选项卡激活事件。 Something like this:像这样的东西:

{
    "xtype": "tabpanel",
    "tabPosition": "left",
    "layout": "fit",
    "tabRotation": 0.0,
    "items": [{
        "xtype": "panel",
        "title": "tab1",
        "icon": "classic/resources/images/Profile_active.png",
        "layout": "card",
        "items": [{
            "xtype": "panel",
            "title": "tab1panel1",
            html: "Tab1Panel1"
        }]
    }, {
        "xtype": "panel",
        "title": "tab1",
        "icon": "classic/resources/images/Profile_active.png",
        "layout": "card",
        "items": [{
            "xtype": "panel",
            "title": "tab2panel1",
            html: "Tab2Panel1"
        }, {
            "xtype": "panel",
            "title": "tab2panel2",
            html: "Tab2Panel2"
        }],
        listeners: {
            activate: function (panel) {
                // Some random condition
                const activeItemIndex = Math.round(Math.random());
                panel.setActiveItem(activeItemIndex);
            }
        }
    }]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM