2012-07-12 3 views
2

다음 양식이 있습니다. 사용자가 텍스트 파일 uname에 입력 한 값을 인쇄해야합니까? 내가 어떻게 할 수 있니?양식 값 인쇄

Ext.create('Ext.form.Panel', { 
    title: 'Basic Form', 
    renderTo: Ext.getBody(), 
    bodyPadding: 5, 
    width: 350, 

    // Any configuration items here will be automatically passed along to 
    // the Ext.form.Basic instance when it gets created. 

    // The form will submit an AJAX request to this URL when submitted 
    url: 'save-form.php', 

    items: [{ 
     fieldLabel: 'NAME', 
     name: 'uname' 
    }], 

    buttons: [{ 
     text: 'Submit', 
     handler: function() { 
      // The getForm() method returns the Ext.form.Basic instance: 
      var form = this.up('form').getForm(); 
      if (form.isValid()) { 

       // CONSOLE.LOG (FORM VALUES) /////////////////////////////////////// 

      } 
     } 
    }] 
}); 

답변

2

필드의 형태로 모든 값이 포함 된 개체를 얻을 수있는 getValues 방법을 사용 : 또는

var form = this.up('form').getForm(); 
if (form.isValid()) { 
    var values = form.getValues(); 

    // log all values. 
    console.log(values); 

    // log uname value. 
    console.log(values['uname']); 
} 

를 양식 내의 특정 필드에 액세스 할 수 findField 방법을 사용하십시오

var form = this.up('form').getForm(); 
if (form.isValid()) { 

    // log uname value. 
    var field = form.findField('uname'); 
    console.log(field.getValue()); 
} 

예 :http://jsfiddle.net/5hndW/