当我执行以下代码时,我可以在记录的 chrome 中看到一个异常,如下所示:
未捕获的类型错误:对象 [对象对象] 没有方法"getEl"
var search = new Ext.form.Panel({
renderTo: 'pan',
title: 'Basic Panel',
collapsible:true,
width: 400,
defaults: {width: 230},
defaultType: 'textfield',
bodyPadding: 10,
//layout: 'form',
frame:true,
items: [{
fieldLabel: 'Username',
name: 'username',
id: 'username',
allowBlank:false
},
{
fieldLabel: 'Password',
name: 'password',
inputType:'password',
allowBlank:false
},
{
fieldLabel: 'First Name',
name: 'firstname',
inputType:'text',
allowBlank:false
},
{
fieldLabel: 'Last Name',
name: 'lastname',
inputType:'text',
allowBlank:false
},
{
fieldLabel: 'E-Mail Address',
name: 'email',
vtype:'email',
allowBlank:false
},
{
fieldLabel: 'State',
name: 'state',
allowBlank:false
},
{
fieldLabel: 'City',
name: 'city',
allowBlank:false
},
{
fieldLabel: 'Country',
name: 'country',
allowBlank:false
},
{
inputType: 'hidden',
id: 'submitbutton',
name: 'myhiddenbutton',
value: 'hiddenvalue'
}
],
buttons: [{
text: 'Submit',
handler: function() {
search.getForm().getEl().dom.action = 'FormServlet';
search.getForm().getEl().dom.method = 'POST';
search.getForm().submit();
}
}]
我已经在web.xml文件中定义了servlet,其中包含名称,类和url。
请让我知道如何解决此问题。
问候
不要让它变得那么复杂。我猜 ExtJS 会覆盖您的设置或根本没有使用它们,因为您没有使用适当的配置属性来设置它。
以下是两者的 API 链接
- 方法
- 网址
这是您使用这些扩展的演示代码
var search = new Ext.form.Panel({
renderTo: 'pan',
title: 'Basic Panel',
collapsible:true,
width: 400,
defaults: {width: 230},
defaultType: 'textfield',
bodyPadding: 10,
url: 'FormServlet', // you can fix a parameter like this : FormServlet?action=create
action: 'POST',
frame:true,
items: [
//....
],
buttons: [{
text: 'Submit',
handler: function() {
search.getForm().submit();
}
}]
或者这样做是为了更灵活
var search = new Ext.form.Panel({
renderTo: 'pan',
title: 'Basic Panel',
collapsible:true,
width: 400,
defaults: {width: 230},
defaultType: 'textfield',
bodyPadding: 10,
url: 'FormServlet',
action: 'POST',
frame:true,
items: [
//....
],
buttons: [{
text: 'Submit',
handler: function() {
Ext.Ajax.request({
url : 'FormServlet',
method:'POST',
params : {
yourParam: Ext.encode(form.getValues())
},
scope : this,
//method to call when the request is successful
success : this.onLoginSuccess,
//method to call when the request is a failure
failure : this.onLoginFailure
});
}
}]