ExtJs 手动触发 Click 事件,按钮参数与鼠标点击不同 [英] ExtJs manually firing Click event, button param is different from mouse click
问题描述
所以,我有一个登录控制器,您可以用鼠标单击登录或按 Enter 键,如下所示:
So, I have a login controller, you can click login with mouse or press Enter key, like this:
Ext.define('My.controller.Login', {
extend: 'Ext.app.Controller',
init: function(application) {
this.control({
"#idLogin button": {click: this.onButton},
"#idLogin form > *": {specialkey: this.onKey}
});
},
onButton: function(button, e, eOpts) {
var win = button.up('window'); // the login window
//do more stuff...
},
onKey: function (field, el) {
if (el.getKey() == Ext.EventObject.ENTER) //ENTER key performs Login
Ext.getCmp('#idLogin button').fireEvent('click');
}
});
我发现当我用鼠标点击登录按钮时,onButton
函数正常工作,button.up()
返回我登录window代码>.
I realised when I use the mouse to click the Login button, onButton
function works properly, button.up()
returns me the Login window
.
但是,如果我按下 Enter 键并触发 onKey
函数来执行 fireEvent('click')
,在本例中为 onButton
启动但参数 button
与您点击鼠标时收到的 button
参数不同!而这一次,button.up()
函数未定义.
However, if I pressed Enter key and fires the onKey
function to do fireEvent('click')
, in this case the onButton
fires up but parameter button
NOT the same as the button
parameter received when you click by mouse! And this time, button.up()
function is undefined.
问题是,为什么 fireEvent('click')
给我一个不同的按钮参数?
Question is, why does fireEvent('click')
give me a different button parameter?
推荐答案
你必须像这样使用 fireEvent
函数:
You must use the fireEvent
function like that:
var myBtn = Ext.getCmp('#idLogin button');
myBtn.fireEvent('click', myBtn);
试试看.
这篇关于ExtJs 手动触发 Click 事件,按钮参数与鼠标点击不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!