2012-07-12 71 views
2

我有以下表单。我需要输出用户为textfiled 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/