【问题标题】:In extjs MVC architecture how to pass parameter to function在 extjs MVC 架构中如何将参数传递给函数
【发布时间】:2013-11-29 07:19:25
【问题描述】:

我想将参数“aaa”传递给 disableFlied 函数,但下面的代码不起作用:

init: function() {

    this.control({
        '#speedCheck': {
            change :this.disableFlied("aaa")
        }
    });

},
disableFlied: function(cmpName){

    var a = Ext.getCmp(cmpName);
    a.setDisabled(!a.isDisabled());

}

如何将“aaa”传递给disableFlied函数?

【问题讨论】:

    标签: extjs extjs4 extjs-mvc


    【解决方案1】:

    您必须传递一个函数作为事件处理程序,在这里您传递的是自己调用disableField 的结果(即没有任何内容,因为此方法不返回任何内容)。您需要做的是创建另一个传递所需参数的函数。在 Ext 中,您可以使用 Ext.bind 函数来做到这一点。

    你应该如何使用它:

    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');
            }
        }
    

    【讨论】:

    • this.control({ '#speedCheck': { change: Ext.bind(this.disableField, this, ['aaa']) } this });
    • 如果您复制/粘贴了我的示例,请注意我写了disableField,而您在代码中的disableFlied 有错字。
    • 如果这仍然不起作用,这可能表明您的代码中的其他地方有错误...您需要提供更多详细信息以获得进一步的帮助。从如何开始,它不起作用。
    • 我是stackoverflow的新用户,不熟悉如何使用,只是标记了:)
    猜你喜欢
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 2020-05-04
    相关资源
    最近更新 更多