在extjs MVC架构中如何将参数传递给函数
我想将参数“aaa”传递给disableFlied函数,但下面的代码不起作用:在extjs MVC架构中如何将参数传递给函数,extjs,extjs4,extjs-mvc,Extjs,Extjs4,Extjs Mvc,我想将参数“aaa”传递给disableFlied函数,但下面的代码不起作用: init: function() { this.control({ '#speedCheck': { change :this.disableFlied("aaa") } }); }, disableFlied: function(cmpName){ var a = Ext.getCmp(cmpName); a.setDis
init: function() {
this.control({
'#speedCheck': {
change :this.disableFlied("aaa")
}
});
},
disableFlied: function(cmpName){
var a = Ext.getCmp(cmpName);
a.setDisabled(!a.isDisabled());
}
如何将“aaa”传递给disableFlied函数?您必须将函数作为事件处理程序传递,这里您将自己传递调用disableField的结果(即,由于此方法不返回任何内容,因此没有任何内容)。您需要做的是创建另一个传递所需参数的函数。在Ext中,您可以使用函数来实现这一点 以下是您应该如何使用它:
this.control({
'#speedCheck': {
change: Ext.bind(this.disableField, this, ['aaa'])
}
});
这将围绕disableField
方法创建一个闭包。这
相当于以下普通javascript代码:
'#speedCheck': {
// This is the default scope, but I prefer to make it
// explicit that the handler must be called in the
// current scope
scope: this
,change: function() {
// When this function is called, it will call
// disableField with the desired parameter
this.disableField('aaa');
}
}
您必须将函数作为事件处理程序传递,这里您要传递自己调用
disableField
的结果(即,由于此方法不返回任何内容,所以没有任何内容)。您需要做的是创建另一个传递所需参数的函数。在Ext中,您可以使用函数来实现这一点
以下是您应该如何使用它:
this.control({
'#speedCheck': {
change: Ext.bind(this.disableField, this, ['aaa'])
}
});
这将围绕disableField
方法创建一个闭包。这
相当于以下普通javascript代码:
'#speedCheck': {
// This is the default scope, but I prefer to make it
// explicit that the handler must be called in the
// current scope
scope: this
,change: function() {
// When this function is called, it will call
// disableField with the desired parameter
this.disableField('aaa');
}
}
控件({speedCheck':{change:Ext.bind(this.disableField,this,['aaa'])}this});如果您复制/粘贴了我的示例,请注意我编写了
disableField
,而您在代码中键入了disableField
。如果这仍然不起作用,则可能表明代码中的其他地方有错误。。。您需要提供更多详细信息以获得进一步帮助。我是stackoverflow的新用户,不熟悉如何使用它,只是标记:)this.control({#speedCheck':{change:Ext.bind(this.disableField,this,['aaa'])}this});如果您复制/粘贴了我的示例,请注意我编写了disableField
,而您在代码中键入了disableField
。如果这仍然不起作用,则可能表明代码中的其他地方有错误。。。您需要提供更多详细信息以获得进一步帮助。我是stackoverflow的新用户,不熟悉如何使用它,只是标记:)