ExtJS 4 - 异步回调callParent抛出异常 [英] ExtJS 4 - async callback to callParent throws exception

查看:459
本文介绍了ExtJS 4 - 异步回调callParent抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



>然而, me.callParent()在没有异步回调的情况下工作得很好。

  Ext.define('My.desktop.AppExt',{
extends:'Ext.ux.desktop。应用程序'

someStore:null,

init:function(){
var me = this;
me.someStore = Ext.create 'my.store.SomeStore');
me.someStore.load({
scope:this,
url:'some / json / url',
callback:function记录,选择,成功){
if(success){
me.callParent(); // BOOM!E​​RROR HERE
}
}
});
}
});

错误:



行处理未处理的异常4245,第17列在//localhost/js/ext-all-debug.js中



0x800a138f - JavaScript运行时错误:



无法获取未定义或空引用的属性超类

解决方案

callParent依赖在上下文中调用正确的方法,所以如果你不是从子类方法直接调用它,你需要手动调用它:

  Ext.define('A',{
foo:function(){
console.log('foo','a');
}
});

Ext.define('B',{
extends:'A',
bar:function(){
this.self.superclass.foo.call (this);
}
});

Ext.onReady(function(){
var o = new B();
o.bar();
});


I want to prepare some Json Store before processing to callParent(), then it throws an error.

However, me.callParent() works fine outside without async callback.

Ext.define('My.desktop.AppExt', {
    extend: 'Ext.ux.desktop.App',

    someStore: null,

    init: function() {
        var me = this;
        me.someStore = Ext.create('My.store.SomeStore');
        me.someStore.load({
            scope: this,
            url: 'some/json/url',
            callback: function(records, opt, success) {
                 if (success) {
                     me.callParent(); // BOOM! ERROR HERE
                 }
            }
        });
    }
});

ERROR:

Unhandled exception at line 4245, column 17 in //localhost/js/ext-all-debug.js

0x800a138f - JavaScript runtime error:

Unable to get property 'superclass' of undefined or null reference

解决方案

callParent relies on the context to call the right method, so if you're not actually calling it "directly" from a subclass method, you'll need to invoke it manually:

Ext.define('A', {
    foo: function(){
        console.log('foo', 'a');    
    }
});

Ext.define('B', {
    extend: 'A',
    bar: function(){
        this.self.superclass.foo.call(this);    
    }
});

Ext.onReady(function(){
    var o = new B();
    o.bar();
});

这篇关于ExtJS 4 - 异步回调callParent抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆