[英]calling wrong method ExtJS
I have this piece of code : 我有这段代码:
listeners:
{
beforerender: function()
{
if (importButton == true)
{
this.menu.add(
{
text: 'Import',
iconCls: 'importIcon',
listeners:
{
click: new ifAuthorizing('import')
}
})
}
this.menu.add(
{
text: 'Consultation',
iconCls: 'searchIcon',
listeners:
{
click: menuConsultation
}
})
}
}
that is supposed to add items to a menu when some conditions are OK. 当某些条件确定时,应该将项目添加到菜单。
It's working, the button are well added if the conditions matches. 它正在工作,如果条件匹配,则可以很好地添加按钮。
The problem is coming from the 问题出在
listeners:
{
click: new ifAuthorizing('import')
}
This listener is supposed to be appended to the menu item, but it is triggered during the beforerender event of its parent. 该侦听器应该附加在菜单项上,但是会在其父项的prerender事件期间触发。
function ifAuthorizing(arg) {
console.log('import')
}
The 'import' is displayed in the console logs during the beforerender event, and then if I click on the menu item that is supposed to have a click method, nothing happens. 在beforerender事件期间,控制台日志中会显示“导入”,然后,如果我单击应该具有单击方法的菜单项,则不会发生任何事情。
I would like to know why. 我想知道为什么。
new ifAuthorizing('import')
Here operator new tries to create an object and interpretes ifAuthorizing as a constructor. 在这里,operator new尝试创建一个对象,并将ifAuthorizing解释为构造函数。 The constructor is called immediately, that's why it fires on beforeRender event. 构造函数被立即调用,这就是为什么它在beforeRender事件上触发的原因。 As a result you get some object which is not a copy of function ifAuthorizing, so it can't be called on menu item's event with the desired result. 结果,您得到的不是函数ifAuthorizing的副本的对象,因此无法在菜单项的事件上以所需的结果调用该对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.