2011-09-05 65 views
0

我有一個formpanel被擴展到一個從另一個文件調用的類。 設置的工作原理是正確顯示。this.getForm問題在擴展ExtJS FormPanel

我面臨的問題是,當我按下提交按鈕時,我一直在Firebug中收到一個錯誤「this.getForm不是函數」。

我的代碼是從一個教程採取與我完全相同的設置,所以我不明白爲什麼我不斷收到此錯誤。

SearchForm = Ext.extend(Ext.FormPanel, { 
    id: 'myForm' 
    ,title: 'Search Form' 
    ,frame:true  
    ,waitMessage: 'Please wait.'   
    ,initComponent: function() {  
     var config = {     
      items: [{ 
       layout:'column', 
       items:[{ 
        columnWidth:.3, 
        layout: 'form', 
        items: [{ 
         xtype:'combo',        
         id: 'reportSelecCmb1',        
         hiddenName: 'ddi_country',       
         anchor:'98%', 
         store: dateStore, 
         displayField: 'name', 
         valueField: 'alpha2code', 
         selectOnFocus: true, 
         mode: 'local', 
         typeAhead: true, 
         editable: false, 
         triggerAction: 'all', 
         value: 'report_date', 
         listeners: { 
          select: { 
           fn:function(combo, value){ 
            myStore.load({params:{ddi_country: this.value}}); 
             } 
            } 
           } 
          }, 
         ... 
       }], 
       buttons: [{ 
        text: 'Submit', 
        id: "submitBtn",      
        handler: this.submit 
       },{ 
        text: 'Reset' 
       }] 
      }]}; 

      // apply config 
      Ext.apply(this, config); 
      Ext.apply(this.initialConfig, config); 

      SearchForm.superclass.initComponent.apply(this, arguments);  

     } 

    ,submit : function(url, waitMsg) { 
     this.getForm().submit({ 
      url: url 
      ,scope: this 
      ,waitMsg: waitMsg 
      ,success: this.onSuccess 
      //,failure: this.onFailure 
     }) 
    } 

    ,onSuccess: function(form, action) {  
     Ext.Msg.show({ 
      title: 'Success'  
      ,msg: 'Success!'  
      ,modal: true  
      ,icon: Ext.Msg.INFO 
      ,buttons: Ext.Msg.OK  
     }); 
    } 

}); 

回答

1

您的按鈕有問題。

通過添加這個指向範圍更改按鈕定義如下:

buttons: [{ 
    text: 'Submit', 
    id: "submitBtn",      
    handler: this.submit, 
    scope: this 
},{ 
    text: 'Reset' 
}] 

希望它能幫助。

+0

這工作,但它給我一個404錯誤,我沒有指定,並沒有顯示消息框。錯誤是請求的資源(/ main/prog/app /%5Bobject%20Object%5D)不可用。我已經在一個虛擬url中添加了一個formpanel,但它並沒有什麼區別 – pm13

+0

查看一個按鈕的'click' * event *('handler'),並將其與submit'* method *進行比較。查看匹配結果,如果不匹配,則嘗試確定如何在'submit' *方法*中獲得所需的信息。 – Chau