Programmatically call handler of a button event?

一曲冷凌霜 提交于 2020-01-04 15:29:41

问题


How can I call a handler from an button event? I want to click event a button and call that button handler?

Ext.getCmp('buttonID').click();
/// How to fire handler of that button?

回答1:


You may get this way:

var button = Ext.getCmp('buttonID'); 
button.fireEvent('click', button);

The second param must be button if you want to keep hanlder logic equals to common button's clicking




回答2:


Ext itself does it this way:

var btn = Ext.getCmp('buttonID');
var e = null; // we don't have any event, so let's use nothing
Ext.callback(btn.handler, btn.scope, [btn, e], 0, btn);

If your handler depends on the event, it will not work...



来源:https://stackoverflow.com/questions/29834028/programmatically-call-handler-of-a-button-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!