【问题标题】:Using createDelegate in extjs在 extjs 中使用 createDelegate
【发布时间】:2013-03-12 12:16:04
【问题描述】:

这是我第一次尝试在 IE9 的 extjs(4.0.1) 中将用户定义的参数传递给处理函数。我有下面的代码,但它会抛出一个错误,指出SCRIPT438: Object doesn't support property or method 'createDelegate'。我不确定我做错了什么。请帮忙。

js文件:

Ext.onReady(function() {

    var appendBooleanOrInsertionIndex = 0; 
    var myButtonHandler = function(item,a, b, arg){
           alert(a + " "+ b);
        };

var myButton = new Ext.Button({
       id : 'myButton',
       //renderTo : 'mybutton',
       text : 'Save',
       handler : myButtonHandler.createDelegate(this, ['Hi', 'Kart'], appendBooleanOrInsertionIndex),
       scope : this
    });
});

【问题讨论】:

    标签: extjs4


    【解决方案1】:

    Ext 停止向 Ext 4 中的原生类原型添加逻辑。请使用 Ext.Function.bindExt.Function.pass

    【讨论】:

    • 嗨..感谢您的回复。我尝试了绑定和传递,但在 ext-all-debug.js 文件中出现错误 SCRIPT438:对象不支持属性或方法“应用”。不确定它是什么。请帮助...
    • 你如何调用绑定/传递?这应该工作handler: Ext.Function.pass(myButtonHandler, ['Hi, 'Kart'])。您是否包含任何其他可能与 Array 原型混淆的库?
    • 您好,wanokok,我太笨了,在函数语法中漏掉了一个逗号,导致错误。你说的对。使用Ext.Function.pass 成功了。更正的代码在我的答案中。非常感谢。
    【解决方案2】:

    修正后的代码如下:

    Ext.onReady(function() {
    
    
        var myButtonHandler = function(a, b){//alert("-->");
               alert(a + " "+ b);
            };
    
            Ext.create('Ext.panel.Panel', {
                renderTo: Ext.getBody(),
                width: 800,
                height: 300,
                layout: 'column',
                title: 'Container Panel',
                //html: 'parent panel',
                items: [
                    {
                        xtype: 'button',
                        id: 'mbutton',
                        text : 'My Button',
                        handler : Ext.Function.pass(myButtonHandler, ['Hi', 'Kart!!!!'])
                    }
                ]
            });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多