ExtJS 4.2.1不使用standardSubmit提交表单

roh*_*han 1 extjs extjs4.2

我正在尝试通过post方法提交表单,使用extjs 4.2.1中的standardSubmit在新窗口中打开一个url

在getFields函数中,ext-all-debug.js抛出错误

getFields: function() {
    return this.monitor.getItems();
},
Run Code Online (Sandbox Code Playgroud)

未捕获的TypeError:无法调用null的方法'getItems'

在这里,显示器对象被示为空.

单击链接将打开一个包含表单的消息窗口.单击"是",表单必须在打开新窗口的情况下提交.

我的表格是:

initComponent: function() {
    var me = this;

    Ext.applyIf(me, {
        items: [
        {
            xtype: 'form',
            flex: 1,
            itemId: 'importForm',
            layout: {
                align: 'center',
                type: 'vbox'
            },
            bodyPadding: 20,
            standardSubmit: true,
            items: [
            {
                xtype: 'hiddenfield',
                itemId: 'user_id',
                fieldLabel: 'Label',
                name: 'user_id'
            },
            {
                xtype: 'label',
                itemId: 'formLabel',
                padding: 5,
                text: 'My Label'
            },
            {
                xtype: 'container',
                margin: '10 0 0 0',
                layout: {
                    align: 'middle',
                    pack: 'center',
                    type: 'hbox'
                },
                items: [
                {
                    xtype: 'button',
                    itemId: 'btnImport',
                    margin: '20 0 0 0',
                    width: 75,
                    text: 'Yes'
                },
                {
                    xtype: 'button',
                    cls: 'btn-no',
                    itemId: 'btnCancel',
                    margin: '0 0 0 10',
                    width: 75,
                    text: 'No'
                }]
            }]
        }]
    });
Run Code Online (Sandbox Code Playgroud)

提交表单的代码是:

me.form.getForm().doAction('standardsubmit',{
    target : '_blank',
    method : 'POST',
    standardSubmit:true,
    url : 'http://www.mysite.com'
});
Run Code Online (Sandbox Code Playgroud)

完全相同的代码在Extjs 4.1.3中有效,但在4.2.1中显示错误

这是一个错误还是我的代码有问题???

roh*_*han 8

找到了错误的原因.表单提交下面的代码有一个关闭窗口的语句,它抛出了异常.

me.form.getForm().doAction('standardsubmit',{
    target : '_blank',
    method : 'POST',
    standardSubmit:true,
    url : 'http://www.mysite.com'
});
me.abstractcomponent.close(); <----- THIS CAUSED THE ERROR
Run Code Online (Sandbox Code Playgroud)

原因可能是窗体在表单等待/响应某些操作时立即关闭.

添加setTimeout()事件就可以了:

setTimeout(function(){me.abstractcomponent.close();},500);
Run Code Online (Sandbox Code Playgroud)

希望它对别人也有用!!!