javascript - 在 ExtJS 4 的 tabpanel 中,如何在每次单击选项卡时捕获 tabchange 事件?

标签 javascript extjs tabpanel floating

对于选项卡面板中的每个选项卡,我都有一个位于固定位置的 float 面板。当我切换标签时,我需要将相应的 float 面板带到前面。但是,tabchange 事件仅在第一次触发。单击选项卡时如何捕获此选项卡更改或其他类似事件?

Alexey,这是我的示例代码,其中包含更具体的问题:

Ext.onReady(function() {
    panel1 = Ext.create('Ext.panel.Panel', {
        title: 'title1', width: 800, height: 50,
        listeners: { 'beforeshow': { fn: function() { 
            console.log("beforeshow on title1"); 
        }, scope: this, single: true } }
    });
    panel2 = Ext.create('Ext.panel.Panel', {
        title: 'title2', width: 800, height: 50,
        listeners: { 'beforeshow': { fn: function() { 
            console.log("beforeshow on title2"); 
        }, scope: this, single: true } }
    });
    panel3 = Ext.create('Ext.panel.Panel', {
        title: 'title3', width: 800, height: 50,
        listeners: { 'beforeshow': { fn: function() { 
            console.log("beforeshow on title3"); 
        }, scope: this, single: true } }
    });
    var tabpanel = Ext.createWidget('tabpanel', {
        renderTo: document.body,
        activeTab: 0,
        width: 800, height: 50, plain: true,
        items: [panel1, panel2, panel3],
        listeners: {
            'tabchange': { fn: function() {
                 console.log("tabchange");
            }, scope: this, single: true }
        }
    });
});

“tabchange”消息只打印一次。我真正想要的是在每次单击选项卡时显示消息“beforeshow on ...”。

Leoh,你就是那个男人!原来我的代码中的问题是“fn”。通过删除“fn”、“scope”和“single”,以下代码可以完美运行。我不知道为什么。谁能解释一下?

Ext.onReady(function() {
    panel1 = Ext.create('Ext.panel.Panel', {
      title: 'title1', width: 800, height: 50,
      listeners: { 'beforeshow': function() { console.log("beforeshow on title1"); } }
    });

    panel2 = Ext.create('Ext.panel.Panel', {
      title: 'title2', width: 800, height: 50,
      listeners: { 'beforeshow': function() { console.log("beforeshow on title2"); } }
    });

    panel3 = Ext.create('Ext.panel.Panel', {
      title: 'title3', width: 800, height: 50,
      listeners: { 'beforeshow': function() { console.log("beforeshow on title3"); } }
    });

  var tabpanel = Ext.createWidget('tabpanel', {
    renderTo: document.body,
    activeTab: 0,
    width: 800,
    height: 50,
    plain: true,
    items: [panel1, panel2, panel3],
    listeners: {
        'tabchange': function() {
             console.log("tabchange");
        }
    }
  });
});

最佳答案

请为事件标签更改附加一个函数

Ext.onReady(function () {
    panel1 = Ext.create('Ext.panel.Panel', {
        title: 'title1'


    });
    panel2 = Ext.create('Ext.panel.Panel', {
        title: 'title2'

    });
    panel3 = Ext.create('Ext.panel.Panel', {
        title: 'title3'

    });
    var tabpanel = Ext.createWidget('tabpanel', {
        renderTo: document.body,
        activeTab: 0,
        width: 800,
        height: 50,
        plain: true,
        items: [panel1, panel2, panel3],
        listeners: {
            'tabchange': function (tabPanel, tab) {
                console.log(tabPanel.id + ' ' + tab.id);
            }
        }
    });
});

Live Demo Here

关于javascript - 在 ExtJS 4 的 tabpanel 中,如何在每次单击选项卡时捕获 tabchange 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14635476/

相关文章:

javascript - 在 Javascript 中根据用户对对象进行分组

javascript - 使用 Javascript 将页脚保持在底部

javascript - 在 MathML 渲染中使用命名空间

javascript - Sencha Touch 中是否有声明全局变量的选项

javascript - ExtJS:检查窗口状态(最小化、最大化等)

java - 删除 GXT Tabpanel 的默认关闭选项卡选项?

javascript - extjs tabpanel 需要在 mozilla firefox 浏览器中单击两次选项卡

javascript - 带有切换按钮的 jQuery 幻灯片动画 div 每隔一段时间而不是每次都工作

javascript - ExtJS 6 - 隐藏组件时停止事件委托(delegate)?