简体   繁体   English

ExtJS对用户点击tabpanel中的选项卡做出反应

[英]ExtJS react to user clicks on tab in tabpanel

(Yes, I know this is similar to How can I attach an react to user clicking on tabs in Ext.TabPanel , but it is a different question) (是的,我知道这类似于如何附加对用户点击Ext.TabPanel中的选项卡的反应 ,但这是一个不同的问题)

I have a tabpanel, the panels of which can be accessed either by clicking on a tab, or by clicking links in other tabs. 我有一个tabpanel,可以通过单击选项卡或单击其他选项卡中的链接来访问其面板。 One tab in the tabpanel has a menu for the user to select the desired subpanel. 选项卡面板中的一个选项卡有一个菜单供用户选择所需的子面板。 What I am trying to achieve is that clicking on the tab does not activate it - thus forcing the user to select an option from the menu. 我想要实现的是单击选项卡不会激活它 - 从而迫使用户从菜单中选择一个选项。 However, I still want the panel to activate when a link on another panel is clicked, or when a menu option is selected. 但是,我仍然希望在单击另一个面板上的链接时,或者选择菜单选项时激活面板。

This is how I disable the panel: 这是我禁用面板的方式:

'beforeactivate': function (component, eOpts) {
    //to prevent loading tab content on tab/menu click
    console.debug('tab disabler', arguments);
    return false;
}

It works - just works too well, blocking everything. 它工作 - 只是工作得很好,阻止一切。 I have not been able to find a way to detect the difference between clicking the tab and, well, doing anything else at all. 我无法找到一种方法来检测单击选项卡之间的区别,以及完成任何其他操作。

Basically you already described the problem: you want to prevent activation of the tab only when the tab header is clicked, not altogether, so the beforeactivate event is not the way to go. 基本上您已经描述了这个问题:您只想在单击选项卡标题时阻止激活选项卡,而不是完全beforeactivate ,因此不能使用beforeactivate事件。

You can access the tab header (which is basically just a button in the tab bar) via the tab property on the panel and prevent the execution of its handler by stopping the propagation of the click event: 您可以通过面板上的tab属性访问选项卡标题 (基本上只是选项卡栏中的一个按钮),并通过停止click事件的传播来阻止其处理程序的执行:

panel.tab.on({
    'click': function(tab, e) {
        e.stopEvent();
    }
});

Note: the docs say you can also return false to achieve the same, however that does not seem to work. 注意:文档说你也可以返回false来实现相同的功能,但这似乎不起作用。

This won't affect activation of the panel at all, but the interaction on the tab header. 这根本不会影响面板的激活,而是会影响选项卡标题上的交互。

Check out this fiddle for a working example. 看看这个小提琴是否有一个实例。

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

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