javascript - this.fireEvent 不工作 extjs3

标签 javascript extjs extjs3

我正在使用 extjs 3 构建自己的类(许可证问题)

Ext.ux.MyClass = Ext.extend(Ext.Container, {

       initComponent: function() {       
                this.button = new Ext.Button({
                                       scope:this,
                                       text:'my button', 
                                       handler: function() {
                                                     alert(0);
                                                     this.fireEvent('myevent');
                                       }
                });

                this.addEvents('myevent');
       }    
});


//in the code:

var obj = new Ext.ux.MyClass(...);

obj.on('myevent', function () {alert(1);});

事件没有被触发代码没有给出错误我可以看到警报(0)但不是警报(1);

我尝试了监听器但也没有工作,this.fireEvent 返回 true。

谢谢你的帮助

最佳答案

您使用的是什么版本的 ExtJS 3? 3.0、3.1 还是 3.4?

如果它是 3.4,那么它似乎对我有用。我添加了一些额外的代码只是为了让按钮呈现,但对我来说似乎没问题。

我使用的最终代码是:

Ext.onReady(function(){

    Ext.ux.MyClass = Ext.extend(Ext.Container, {
        initComponent: function() {
            this.button = new Ext.Button(
            {
                renderTo: document.body,
                scope:this,
                text:'my button', 
                handler: function() {
                    alert(0);
                    this.fireEvent('myevent');
                }
            });

            this.addEvents('myevent');
        }

    });

    var obj = new Ext.ux.MyClass();

    obj.on('myevent', function () {alert(1);});
});

在这里查看 jsfiddle:http://jsfiddle.net/J9YcL/

如果有任何不同,我会在 Chrome 中运行。

关于javascript - this.fireEvent 不工作 extjs3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15257978/

相关文章:

javascript - 在 ExtJS 中居中对齐按钮

javascript - 固定动态表中的编号

javascript - 在 JavaScript 中将整数转换为十六进制字符串

javascript - Hbox 布局面板在调整大小事件后不会自动调整项目

extjs - 销毁窗口后如何处理传入的ajax请求?

javascript - extjs 3.x 多实例

javascript - 如何在带边框的 ext js 中创建 Layout 2X2 布局?

javascript - 只保留字符串中的数字,十进制数字除外

javascript - httplib(python)可以与页面及其javascript交互吗?

javascript - Ext JS - 验证文本字段