1

当我执行下面的代码时,我可以在我的 chrome 中看到一个异常,如下所示:

未捕获的类型错误:对象 [object Object] 没有方法“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();
        }
    }]

我在包含名称、类和 url 的 web.xml 文件中定义了 servlet。

请让我知道如何解决此问题。

问候,

4

1 回答 1

1

不要把事情弄得那么复杂。我猜 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
            });
        }
    }]
于 2012-09-23T07:41:16.900 回答