【问题标题】:ExtJS 4.2.1 does not submit form using standardSubmitExtJS 4.2.1 不使用 standardSubmit 提交表单
【发布时间】:2013-07-17 08:14:43
【问题描述】:

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

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

getFields: function() {
    return this.monitor.getItems();
},

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

这里 monitor 对象显示为 null。

单击链接会打开一个包含表单的消息窗口。单击“是”时,必须在打开一个新窗口的情况下提交表单。

我的表格是:

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'
                }]
            }]
        }]
    });

提交表单的代码是:

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

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

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

【问题讨论】:

  • 你试过做常规的formPanel.submit方法吗?

标签: extjs extjs4.2


【解决方案1】:

找到错误原因。表单提交下面的代码有一个关闭窗口的语句,这引发了异常。

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

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

添加 setTimeout() 事件可以解决问题:

setTimeout(function(){me.abstractcomponent.close();},500);

希望对其他人也有用!!!

【讨论】:

    【解决方案2】:

    这有助于确定问题。问题是表单对象在异步请求开始之前就被销毁了。处理此问题的更好方法是添加您的请求处理程序,以便在返回响应后立即销毁表单。

    form.submit({
        success: function(form, action) {
          yourcomponent.close();//or destroy();
        },
        failure: function(form, action) {
            yourcomponent.close();//or destroy();
        }
    });
    

    http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.Basic

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 2017-07-09
      相关资源
      最近更新 更多