0

我们正在开发一个网络应用程序。为了保持组件的预配置,我做了很多 Ext.extend 工作。

这是预定义。

在入口处,在index.js中

Ext.setup({
    onReady: function() {
        var app = new App();
    }
});

主类,在App.js中,App 会新增一些卡片组件,比如:

App = Ext.extend(Ext.Panel,{
    initComponent: function(){
        this.sub1 = new Sub_Class_1();
        this.sub2 = new Sub_Class_2();
        this.sub3 = new Sub_Class_3();
        this.items = [this.sub1, this.sub2, this.sub3];
        App.superclass.initComponent.call(this);
        this.sub1.on('Event1', this.Event1_fn, this)
    },
    Event1_fn: function() {
        //some codes
    }
});

问题出现在 Sub_Class_1 的定义中,在Sub_Class_1.js中:

var firefun = function() {
    this.fireEvent('Event1');
};

Sub_Class_1 = Ext.extend(Ext.Panel,{
    //some similar init configure jobs.
    //add *firefun* into this class
})

问题是,如果我在 firefun 中触发事件,程序没有反应。范围有问题吗?社区可以帮助我提出可以用来修复它的建议吗?

4

1 回答 1

0

I solved it. This is indeed due to the scope problem.

To solve it, I pass the eventName, eventListener, scope to the function. Let it can fire within the correct scope. Boom, it works!

Any better solution?

于 2010-12-23T05:46:35.783 回答