2012-02-13 59 views
1

我想弄清楚为什么callParent不工作。ExtJS 4 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

+1

无论如何,一个解决方案是进行同步调用。 – 2012-02-13 14:34:23

+0

这样截获initComponent是非常奇怪的。我建议为此使用特殊事件。 – knalli 2012-09-28 21:19:03

+0

这并不奇怪,异步呼叫是可能的和非常合理的,请参阅下面我的答案。 – Tom 2013-05-05 11:56:40

回答

0

喜朱利安加载Windows物品属性 '超'!

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

 { 
       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!

2

我需要将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 
} 
+0

男人你用这个答案拯救了我的生命,谢谢! – 2014-10-21 21:20:08

1

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

与其说this.callParent();

的你需要调用this.self.superclass.foo.call(this);

foo是你想调用的超类方法。

把它包起来,使其看起来更meanful:

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

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

看到这个:

ExtJS 4 - async callback to callParent throws exception