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

v64noz0r  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(166)

我有选项卡面板。在选项卡开关(第二个选项卡)有时我想在tab2panel1渲染,有时在tab2panel2基于一些条件。这是我的配置。

{
            "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",
                    }]
                },  
            ]
        }

这是我正在尝试的,但它正在更改为tab1。而不是tab 2的面板项。

tabchange: function (tab, newTab, oldTab) {
        let _this = this,
            cardItems = newTab.items;

        if (tab.changeValue == true) {
             newTab.getLayout().setActiveItem(1);
        }
    }

但这导致了1的标签。不是标签内的项目。这里有任何帮助。

v09wglhw

v09wglhw1#

我认为这是错误的地方,更好地听取标签激活事件.类似这样的东西:

{
    "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);
            }
        }
    }]
}

相关问题