Javascript 在ExtJS按钮中使用setHandler时,会立即执行handler函数
我在面板上添加了一个按钮。单击按钮时,将显示一个弹出窗口。我尝试使用setHandler更新弹出窗口的内容。但无论何时调用setHandler,都会立即执行handler函数。下面是示例代码:Javascript 在ExtJS按钮中使用setHandler时,会立即执行handler函数,javascript,button,extjs,Javascript,Button,Extjs,我在面板上添加了一个按钮。单击按钮时,将显示一个弹出窗口。我尝试使用setHandler更新弹出窗口的内容。但无论何时调用setHandler,都会立即执行handler函数。下面是示例代码: me.panels[i].getDockedItems()[0].setHandler(Popup({html: tiphtml}), this); ... Popup = function(cfg) { cfg = Ext.apply({ heigh
me.panels[i].getDockedItems()[0].setHandler(Popup({html: tiphtml}), this);
...
Popup = function(cfg) {
cfg = Ext.apply({
height: 100,
width: 200,
layout: 'fit'
}, cfg);
Ext.create('Ext.window.Window', {
title: cfg.title,
height: cfg.height,
width: cfg.width,
layout: cfg.layout,
html: cfg.html
}).show();
}
您需要将函数嵌套在匿名函数中。您实际上是在代码中调用函数,而不是传递它。这将有助于:
me.panels[i].getDockedItems()[0].setHandler(function(){Popup({html: tiphtml})}, this);
...
Popup = function(cfg) {
cfg = Ext.apply({
height: 100,
width: 200,
layout: 'fit'
}, cfg);
Ext.create('Ext.window.Window', {
title: cfg.title,
height: cfg.height,
width: cfg.width,
layout: cfg.layout,
html: cfg.html
}).show();
}
谢谢你的快速回复。