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) ///////////////////////////////////////

            }
        }
    }]
});
4

1 回答 1

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/

于 2012-07-12T20:52:57.940 回答