如何附加对用户单击 Ext.TabPanel 中的选项卡的反应
当我想对用户在网格上选择一行做出反应时,我使用以下内容:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你很接近了。
选项卡面板内的各个面板在激活时会触发
activate
事件。您可以在配置时通过
listeners
配置键将处理程序附加到 TabPanel 中的每个项目。或者,您可以在执行时迭代连接侦听器的所有选项卡,例如:
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:
您还可以使用 TabPanel 的 'beforetabchange' 事件:
You can also use 'beforetabchange' event of the TabPanel: