ExtJS 4 callParent not working



我正试图弄清楚callParent不起作用的原因。

这里有一些代码:

Ext.define('AM.ArView', {
extend:'Ext.window.Window',
initComponent: function() {
    var foo = this;
    console.log(foo);
    Ext.Ajax.request({
        url: 'http://my/awesome/path',
        success: function(response, opts) {
            console.log(foo);
            foo.callParent();
        },
        failure: function(response, opts) {
            console.log('error');
        }
    });
}
});

错误:未捕获的类型错误:无法读取未定义的属性"superclass"

我需要通过ajax 加载窗口项目

我需要将带有callParent的回调传递到Ext.Msg.*对话框中。老实说,我不知道如何使用答案中的代码来处理我的案件。。。并用黑客破解了它。

在4.0.7:中工作

methodName: function () {
    var me = this,
        args = arguments;
    // do some stuff
    function customCallback() {
        // do some stuff inside callback
        // hacks for calling parent method from callback
        var caller = arguments.callee.caller;
        caller.$owner = me;
        caller.$name = 'methodName';
        me.callParent(args);
    }
    // do more stuff, pass callback anywhere
}

有点晚了,但希望它能帮助其他人。。。

而不是调用this.callParent();

您需要拨打this.self.superclass.foo.call(this);

foo是您要调用的超类方法。

把它包装起来,让它看起来更刻薄:

callParentManually: function (myscope, methodname) {
    myscope.self.superclass[methodname].call(myscope);
}
//and then ...
callParentManually(me, 'initComponent');

请参阅:

ExtJS 4-对callParent的异步回调抛出异常

你好,朱利安!

我需要做一个类似的操作,最后我将ajax请求封装在一个函数中,我将一个回调函数传递到该函数中,以便在请求完成时执行,并从回调中启动窗口。

就代码而言,它将类似于:

//Request function
 LoadThoseDamnWindows: function (callback)
    {
        Ext.Ajax.request({
            url: 'checklist/GetList',
            success: function(response, opts) {
                console.log(response);
                callback.call(this, response);
            },
            failure: function(response, opts) {
                console.log('error');
            }
        });
    }

然后你调用int let,比如点击按钮:

        {
                xtype: 'button',
                text: 'Help',
                iconCls: 'help',
                    scope: this,
                handler: function(){
                    //Call function
                    this.LoadThoseDamnWindows(function(loadedData){
                        Ext.create('Ext.window.Window',{
                            autoShow: true,
                            layout: 'fit',
                            title: "My Cool window",
                            html: "My window content with dynamic loaded data" + loadedData.responseText
                        });
                    });
                }
            }

啊!

最新更新