ExtJS 4 callParent 不工作

发布于 2025-01-05 05:16:30 字数 543 浏览 4 评论 0原文

我试图找出为什么 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项目

I'm trying to figure out why callParent isn't working.

Here's some code:

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

Error:
Uncaught TypeError: Cannot read property 'superclass' of undefined

I need to load the windows items via ajax

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以往的大感动 2025-01-12 05:16:31

嘿朱利安!

我需要执行类似的操作,最后我将 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
                        });

                    });
                }
            }

HTH!

Hei Julian!

I needed to do a similar operation, and i ended up wrappign the ajax request in a function which i pass a callback function into it to execute when the request is done, and from the call back i launch the windows.

In terms of code, it would be something like:

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

then you call int lets, say ona button click:

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

                    });
                }
            }

HTH!

零時差 2025-01-12 05:16:30

我需要将回调与 callParent 传递到 Ext.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
}

I needed to pass callback with callParent into Ext.Msg.* dialog. Honestly I didn't understand how to use code from answer for my case... and solved it with hack.

Working in 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
}
凉城已无爱 2025-01-12 05:16:30

有点晚了,但希望它对其他人有帮助...

而不是调用 this.callParent();

您需要调用 this.self.superclass.foo.call(this); code>

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

要包装它并使其看起来更有意义:

callParentManually: function (myscope, methodname) {
    myscope.self.superclass[methodname].call(myscope);
}

//and then ...
callParentManually(me, 'initComponent');

请参阅:

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

A bit late, but hope it helps others...

Instead of calling this.callParent();

You need to call this.self.superclass.foo.call(this);

foo being the superclass method you want to call.

To wrap it up and make it look more meanful:

callParentManually: function (myscope, methodname) {
    myscope.self.superclass[methodname].call(myscope);
}

//and then ...
callParentManually(me, 'initComponent');

See this:

ExtJS 4 - async callback to callParent throws exception

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文