0

我有 extjs 4.0 控制器:

Ext.define('KS.controller.DailyReport', {
extend: 'Ext.app.Controller',

views: ['report.Daily'],


init: function() {
    this.control({
        'dailyReport button[action=send]': {
            click: this.sendDailyReport
        }
    });
},

sendDailyReport: function(button) {
    var win = button.up('window');

    form = win.down('form');
    form.getForm().waitMsgTarget = form.getEl();
    form.getForm().waitMsg = 'Sending...';
    if (form.getForm().isValid()) { // make sure the form contains valid data before submitting
        form.submit({
            success: function(form, action) {
                Ext.Msg.alert('Success', action.result.msg);
            },
            failure: function(form, action) {
                Ext.Msg.alert('Failed', action.result.msg);
            }
        });
    } else { // display error alert if the data is invalid
        Ext.Msg.alert('Invalid Data', 'Correct them!')
    }
}
});

和 extjs 视图:

Ext.define('KS.view.report.Daily', {
extend: 'Ext.window.Window',
alias: 'widget.dailyReport',

title: 'Daily report',
layout: 'fit',
autoShow: true,
initComponent: function() {
    this.items = [{
        waitMsgTarget: true,
        xtype: 'form',
        url: 'dailyReport.php',
        layout: 'fit',
        waitMsgTarget: true,
        waitMsg: 'Sending...',
        items: [{
            margin: 10,
            xtype: 'datefield',
            name: 'reportDate',
            fieldLabel: 'Report for:',
            format: 'd.m.Y.',
            altFormats: 'd.m.Y|d,m,Y|m/d/Y',
            value: '12.12.2011',
            disabledDays: [0]
        }]
    }];

    this.buttons = [{
        text: 'Send',
        action: 'send'
    },
    {
        text: 'Cancel',
        scope: this,
        handler: this.close
    }];

    this.callParent(arguments);
}
});

如您所见,我尝试在这两个地方设置 waitMsgTarget 和 waitMsg,但是当我单击发送按钮时它没有出现。

怎么了?

4

1 回答 1

2

您实际上只是waitMsg在以下方面滥用:

  1. waitMsg不是Ext.form.BasicOR的配置选项Ext.form.PanelwaitMsg必须在您的Ext.form.action.Submit. 这就是为什么在视图中设置它永远不会起作用。
  2. 在您的控制器中,您正在做同样的事情并将其设置waitMsgExt.form.Basic.

修复很简单。设置waitMsg在您的Ext.form.action.Submit. 因此,只需将其中的行更改为form.submit()

form.submit({
    waitMsg: 'Sending...',
    success: function(form, action) {
            Ext.Msg.alert('Success', action.result.msg);
        },
    //..... your other stuff here
});

并从控制器中删除这些行:

form.getForm().waitMsgTarget = form.getEl();
form.getForm().waitMsg = 'Sending...';

为了完整起见,从视图中删除这两条线(你waitMsgTarget有两次):

waitMsgTarget: true,
waitMsg: 'Sending...',

注意:要定义waitMsgTarget表单本身以外的其他内容,您必须传入目标的id

例如,在您的视图(即表单定义)中,您可能希望更改waitMsgTarget: true为:

waitMsgTarget: 'myWindowID', 
//where myWindowID is the id of the container you want to mask

如需参考,请参阅: http ://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.action.Submit和 http://docs.sencha.com/ext-js/ 4-0/#!/api/Ext.form.Basic

于 2011-09-23T13:47:18.077 回答