2013-11-24 41 views
2

我正在使用Extjs 4.2,下面是代碼。我已經定義了表單Id,但按鈕事件無法獲取值。奇怪的是,當我提交表單時,它會轉到服務器端,我可以獲取字段值。Extjs 4 get form Id

如何給ID值?

Ext.define('App.view.QuestionForm',{ 
    extend  : 'Ext.form.Panel', 
    alias  : 'widget.QuestionForm', 
    requires : ['Ext.data.Store'], 

    bodyPadding : 5, 
    defaults : {xtype : 'textfield' }, 

    id: 'question_form', 

    initComponent : function(){ 
     var me = this; 
     //me.id = 'question_form'; 

     me.items = me.buildItems(); 
     me.dockedItems = me.buildToolbars(); 
     me.callParent(); 
    }, 


    buildItems : function(){ 
     return [ 
     { 
      fieldLabel: 'ID', 
      name: 'id', 
      xtype: 'textfield', 
      anchor: '100%' 
     },   
     ]; 
    }, 
    buildToolbars : function(){ 
     return [{ 
      xtype : 'toolbar', 
      dock: 'top', 
      items : [ 

      { 
       xtype: 'button', 
       text:'Save', 
       handler: function(){ 
        var form = this.up('form').getForm(); 
        console.log("form :"+form.id); //undefined 

        form.submit({url: 'rs/question/save'});     
       } 
      },  


      ] 
     }]; 
    } 

}); 

感謝

+0

你用什麼代替了上面的代碼?對於'this.up('form')。getForm();'我得到了同樣的錯誤'undefined' – Freakyuser

回答

2

您定義Ext.form.Panel組件的ID。 所以在處理程序只需使用:

var form = this.up('form'); 

用於獲取Ext.form.Panel組件的實例。

當您調用Ext.form.Panel組件的方法getForm()時,它將返回基本沒有定義ID的Ext.form.Basic組件。