1

我试图弄清楚为什么 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');
        }
    });
}
});

错误:未捕获的类型错误:无法读取未定义的属性“超类”

我需要通过 ajax 加载 windows 项目

4

3 回答 3

2

我需要将回调传递callParentExt.Msg.*对话框。老实说,我不明白如何在我的案例中使用答案中的代码......并通过 hack 解决了它。

在 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
}
于 2012-07-17T12:25:49.320 回答
1

有点晚了,但希望它可以帮助别人......

而不是打电话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 的异步回调抛出异常

于 2013-05-05T11:34:53.940 回答
0

嘿朱利安!

我需要做一个类似的操作,我最终将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 让我们说单击按钮:

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

                    });
                }
            }

于 2012-02-13T22:03:00.787 回答