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

Tom*_*Tom 2 javascript extjs

我想在处理之前准备一些Json Store callParent(),然后它会抛出一个错误.

但是,me.callParent()没有异步回调,外部工作正常.

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
                 }
            }
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

错误:

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

0x800a138f - JavaScript运行时错误:

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

Eva*_*oli 6

callParent依赖于上下文来调用正确的方法,所以如果你实际上没有从子类方法"直接"调用它,你需要手动调用它:

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();
});
Run Code Online (Sandbox Code Playgroud)