如何附加对用户单击 Ext.TabPanel 中的选项卡的反应

发布于 2024-10-06 08:53:00 字数 1876 浏览 6 评论 0原文

当我想对用户在网格上选择一行做出反应时,我使用以下内容:

var grid = new Ext.grid.GridPanel({
    region: 'center',
    ...
});
grid.getSelectionModel().on('rowselect', function(sm, index, rec){
    changeMenuItemInfoArea(menuItemApplication, 'you are on row with index ' + index)
});   

如何将相同的功能附加到选项卡?如下所示:

var modules_info_panel = new Ext.TabPanel({
    activeTab: 0,
    region: 'center',
    defaults:{autoScroll:true},
    listeners: {
        'tabclick': function(tabpanel, index) {
            changeMenuItemInfoArea(menuItemModules,'you clicked the tab with index ' + index);
        }
    },
    items:[{
            title: 'Section 1',
            html: 'test'
        },{
            title: 'Section 2',
            html: 'test'
        },{
            title: 'Section 3',
            html: 'test'
        }]
});
modules_info_panel.getSelectionModel().on('tabselect', function(sm, index, rec){
    changeMenuItemInfoArea(menuItemModules, 'you are on tab with index ' + index)
});

附录

感谢@timdev,这有效,在这里这就是我识别它是哪个选项卡的方式(只需通过id,我无法获取选项卡的索引,因为我可以获取网格中行的索引):

var modules_info_panel = new Ext.TabPanel({
    activeTab: 0,
    region: 'center',
    defaults:{autoScroll:true},
    items:[{
            id: 'section1',
            title: 'Section 1',
            html: 'test'
        },{
            id: 'section2',
            title: 'Section 2',
            html: 'test'
        },{
            id: 'section3',
            title: 'Section 3',
            html: 'test'
        }]
});

modules_info_panel.items.each(function(tab){
    tab.on('activate',function(panel){
        changeMenuItemInfoArea(menuItemModules, 'you opened the "' + panel.id + '" tab');
    });
});

replaceComponentContent(regionContent, modules_info_panel);

hideComponent(regionHelp);

When I want to react to the user selecting a row on a grid, I use this:

var grid = new Ext.grid.GridPanel({
    region: 'center',
    ...
});
grid.getSelectionModel().on('rowselect', function(sm, index, rec){
    changeMenuItemInfoArea(menuItemApplication, 'you are on row with index ' + index)
});   

how can I attach the same functionality to tabs? something like this:

var modules_info_panel = new Ext.TabPanel({
    activeTab: 0,
    region: 'center',
    defaults:{autoScroll:true},
    listeners: {
        'tabclick': function(tabpanel, index) {
            changeMenuItemInfoArea(menuItemModules,'you clicked the tab with index ' + index);
        }
    },
    items:[{
            title: 'Section 1',
            html: 'test'
        },{
            title: 'Section 2',
            html: 'test'
        },{
            title: 'Section 3',
            html: 'test'
        }]
});
modules_info_panel.getSelectionModel().on('tabselect', function(sm, index, rec){
    changeMenuItemInfoArea(menuItemModules, 'you are on tab with index ' + index)
});

Addendum

Thanks @timdev, that works, and here is how I identify which tab it is (simply via id, I couldn't get the tab's index as I could the row's index in grid):

var modules_info_panel = new Ext.TabPanel({
    activeTab: 0,
    region: 'center',
    defaults:{autoScroll:true},
    items:[{
            id: 'section1',
            title: 'Section 1',
            html: 'test'
        },{
            id: 'section2',
            title: 'Section 2',
            html: 'test'
        },{
            id: 'section3',
            title: 'Section 3',
            html: 'test'
        }]
});

modules_info_panel.items.each(function(tab){
    tab.on('activate',function(panel){
        changeMenuItemInfoArea(menuItemModules, 'you opened the "' + panel.id + '" tab');
    });
});

replaceComponentContent(regionContent, modules_info_panel);

hideComponent(regionHelp);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海少女心 2024-10-13 08:53:00

你很接近了。

选项卡面板内的各个面板在激活时会触发 activate 事件。

您可以在配置时通过 listeners 配置键将处理程序附加到 TabPanel 中的每个项目。

或者,您可以在执行时迭代连接侦听器的所有选项卡,例如:

modules_info_panel.items.each(function(tab){
    tab.on('activate',function(panel){ ... });
}

You're close.

The individual panels inside your tabpanel fire an activate event when activated.

You attach a handler to each item in the TabPanel at configuration time, via the listeners configuration key .

Or you could iterate over all the tabs attaching your listener as you go, something like:

modules_info_panel.items.each(function(tab){
    tab.on('activate',function(panel){ ... });
}
饭团 2024-10-13 08:53:00

您还可以使用 TabPanel 的 'beforetabchange' 事件:

tabs.on('beforetabchange', function(tabPanel, newItem, currentItem) { ... }, this);

You can also use 'beforetabchange' event of the TabPanel:

tabs.on('beforetabchange', function(tabPanel, newItem, currentItem) { ... }, this);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文