我有以下表格。我需要打印用户为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) ///////////////////////////////////////
}
}
}]
});
答案 0 :(得分: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());
}