2012-02-13 64 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