简体   繁体   English

无法捕获选项卡更改事件

[英]Fail to catch tab change event

I'm using button to move between tabs. 我正在使用按钮在标签之间移动。 But for that I have to remember the user's tab position. 但是为此,我必须记住用户的选项卡位置。 So my buttons keep working when the user leaves the screen and returns later. 因此,当用户离开屏幕并稍后返回时,我的按钮将继续工作。

The tabchange event should be the event to use for that, however I cannot get it to trigger. tabchange事件应该是为此使用的事件,但是我无法触发它。

View: 视图:

Ext.define('MyApp1.view.Home',
{
    extend: 'Ext.form.Panel',

    requires:
    [
        'Ext.tab.Panel'
    ],

    xtype: 'home',

    config:
    {
        itemId: 'home',
        layout: 'fit',

        items:
        {
            xtype: 'tabpanel',
            tabBarPosition: 'top',
            height: 500,
            renderTo: document.body,
            listeners:
            {
                beforetabchange: function (tabs, newTab, oldTab)
                {
                    console.log('tab is going to change');
                },
                tabchange: function ()
                {
                    console.log('recorded tab change from listener');
                },
                change: function ()
                {
                    console.log('change of tab from listener');
                }
            },

            items:
            [
                {
                    title: 'one'
                },
                {
                    title: 'two'
                }
            ]
        }
    }
});

Controller: 控制器:

Ext.define('MyApp1.controller.HomeController',
{
    extend: 'Ext.app.Controller',

    requires:
    [
        'MyApp1.view.Main'
    ],

    config:
    {
        refs:
        {
            home: 'home'
        },
        control:
        {
            home:
            {
                beforetabchange: 'onTabChange',
                tabchange: 'onTabChange',
                change: 'onTabChange'
            }
        }
    },

    init: function()
    {
        console.log('HomeController initialized');
    },

    onTabChange: function ()
    {
        console.log('active tab changed');
    }
});

So I see the initialization text in the log but none of the tab change events when I click the tab buttons. 因此,当我单击选项卡按钮时,我在日志中看到了初始化文本,但是没有任何选项卡更改事件。

原来我是在看ExtJs 5文档,而不是Sencha 2.4.1文档...。该文档仅具有'activeitemchange'事件。

First off it seems you can only implement these listeners on the tabBar of the tabPanel 首先,看来您只能在tabPaneltabBar上实现这些侦听器

Having looked through the source code though it seems that this never get's fired even though it is documented. 尽管看过了源代码,即使它已被记录,但似乎永远也不会被解雇。 http://docs-origin.sencha.com/touch/2.4/2.4.1-apidocs/source/Bar3.html#Ext-tab-Bar-event-tabchange http://docs-origin.sencha.com/touch/2.4/2.4.1-apidocs/source/Bar3.html#Ext-tab-Bar-event-tabchange

What I could suggest is either as you pointed out to hook into the activeitemchange event on the panel or activetabchange (which strangely is firing twice) event of the tabbar as activeitemchange also seems not to work as intended. 我所建议的要么是您指出要挂接到面板上的activeitemchange事件,要么是tabbar activetabchange (奇怪地是两次触发)事件,因为activeitemchange似乎也无法按预期工作。

https://fiddle.sencha.com/#fiddle/g44 https://fiddle.sencha.com/#fiddle/g44

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

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