Javascript 在ExtJS中访问事件参数
通常,在创建事件处理程序时,我们会这样做:Javascript 在ExtJS中访问事件参数,javascript,extjs,event-handling,arguments,Javascript,Extjs,Event Handling,Arguments,通常,在创建事件处理程序时,我们会这样做: boxready: function (me, width, height, eOpts) { me.X() <-refers to the component whose event is triggered and calls the function X() } 但是由于我不使用函数(me,…)我无法访问事件发送的参数。我是否有办法访问它们以将它们放入scope属性中?为什么要设置两次作用域?使用范围配置(首选)或Ext.bind。另
boxready: function (me, width, height, eOpts) {
me.X() <-refers to the component whose event is triggered and calls the function X()
}
但是由于我不使用
函数(me,…)
我无法访问事件发送的参数。我是否有办法访问它们以将它们放入scope属性中?为什么要设置两次作用域?使用范围
配置(首选)或Ext.bind
。另外,您正在对myFunction
的返回值调用Ext.bind
,除非myFunction
返回函数本身,否则这是没有意义的
建议的方法:
listeners: {
boxready: function(me, width, height, eOpts) {
//...
},
scope: this
}
listeners: {
boxready: Ext.bind(function(me, width, height, eOpts) {
//...
}, this)
}
或者,如果有多个侦听器需要不同的作用域:
listeners: {
boxready: {
fn: function(me, width, height, eOpts) {
//...
},
scope: this
},
destroy: {
fn: function() {},
scope: this.otherScope
}
}
也有效,但不推荐使用:
listeners: {
boxready: function(me, width, height, eOpts) {
//...
},
scope: this
}
listeners: {
boxready: Ext.bind(function(me, width, height, eOpts) {
//...
}, this)
}
范围:必须始终与此相关吗?我的问题是,我把东西放在一起的方式
这个
指向全局窗口对象。我想要的是将它更改为我的视口,但即使我这样做:Ext.bind(this.myFunction,Ext.getCmp('viewportId'))
它仍然无法工作。。。function(){this},作用域:Ext.getCmp('viewport')
。在这种情况下,它指向具有处理程序的面板。问题在于,您只是在创建视口(即,它还不存在),因此此时自然无法将其设置为范围。