我想知道如何从ExtJS中的表单中获取输入值。 我已经尝试了几种方式"看到评论",但没有一个给我一个价值,我主要得到一个错误 - " undefined"。
另一件不清楚的事情是表格名称定义在哪里?
这是我的代码:
Ext.onReady(function() {
Ext.create('Ext.form.Panel', {
renderTo: document.body,
title: 'Convert Roman characters to Arabic',
height: 150,
width: 300,
bodyPadding: 10,
defaultType: 'textfield',
items: [
{
fieldLabel: 'Enter Roman Character',
name: 'char'
}
],
buttons: [
{
text: 'Submit',
handler: function() {
//var form = formPanel.getForm();
//var value = form.findField('char');
//var form = this.up('form'); // get the form panel
//var value = Ext.getCmp('char').getValue();
// var field = Ext.getCmp('char');
Ext.Msg.alert('Success', "value");
}
}
]
});
});
最后,应用程序应警告输入值。
先谢谢。
答案 0 :(得分:0)
text: 'Submit',
handler: function(btn) {
Ext.Msg.alert('Success',btn.up('form').down('[name=char]').getValue());
答案 1 :(得分:0)
//var form = formPanel.getForm();
//var value = form.findField('char');
//var form = this.up('form'); // get the form panel
//var value = Ext.getCmp('char').getValue();
// var field = Ext.getCmp('char');
There are multi ways to get value of char field.
1) To get value like this as you used, you have to give id property for this field :
{
fieldLabel: 'Enter Roman Character',
name: 'char',
id : 'char' // or give any name
}
now used below code to get value
var field = Ext.getCmp('char');
var value = field.getValue();
2) You can also use itemId property same :
{
fieldLabel: 'Enter Roman Character',
name: 'char',
itemId : 'char' // or give any name
}
now used below code to get value
var field = Ext.ComponentQuery.query('#char')[0];
var value = field.getValue();
3) another way, you can get value from form values;
var form = this.up('form'),
formValues = form.getForm().getValues();
charValue = formValues.char;