ExtJS和事件监听器:未调用'load'。怎么会?

时间:2011-03-24 08:20:39

标签: javascript extjs

这是我的ExtJs组件。 一切都很完美....几乎所有事情都是如此。 我只是不明白为什么没有调用this.on('load', function (form,action) {})而调用this.on('actioncomplete', function (form,action) {});的相同声明:

DossierPanel = Ext.extend(Ext.form.FormPanel, {
    closable: true,
    autoScroll:true,

    initComponent : function(){
        this.id = 'id_dossier_'+this.id_dossier;
        this.bodyStyle = 'padding:15px';
        this.labelWidth = 150;
        this.items = [{
            layout:'column',
            border:false,
            autoHeight: true,
            items:[{
                columnWidth:.5,
                layout: 'form',
                border:false,
                items: [{
                    xtype:'textfield',
                    fieldLabel: 'Civilite ',
                    name: 'CIVILITE',
                    readOnly: true
                }]
            },{
                columnWidth:.5,
                layout: 'form',
                border:false,
                items: [{
                    xtype:'textfield',
                    fieldLabel: 'Email ',
                    name: 'EMAIL',
                    vtype:'email',
                    anchor:'95%'
                }]
            }]
        },{
            xtype:'tabpanel',
            plain:true,
            activeTab: 0,
            deferredRender: false,
            defaults:{bodyStyle:'padding:10px'},
            items:[{
                title:'Détails personnels',
                layout:'form',
                autoHeight: true,
                defaults: {width: '99%'},
                defaultType: 'textfield',

                items: [{
                    xtype:'datefield',
                    fieldLabel: 'Date de naissance ',
                    name: 'NAISSANCEJMA',
                    format:'d/m/Y'
                }]
            },{
                title:'Adresse',
                layout:'form',
                autoHeight: true,
                defaults: {width: '95%'},
                defaultType: 'textfield',
                items: [{
                    fieldLabel: 'Adresse 1 ',
                    name: 'ADRESSE1'
                }]
            },{
                title:'Téléphone(s)',
                layout:'form',
                autoHeight: true,
                defaults: {width: 230},
                defaultType: 'textfield',
                items: [{
                    fieldLabel: 'DescTelephone1 ',
                    name: 'DESCTELEPHONE1',
                    readOnly: true
                }]
            },{
                title:'Divers',
                layout:'form',
                autoHeight: true,
                defaults: {width: 230},
                defaultType: 'textfield',
                items: [{
                    fieldLabel: 'ReferenceExterne ',
                    name: 'REFERENCEEXTERNE'
                }]
            }]
        }];
        this.buttonAlign = 'left';
        this.buttons = [{
            text: 'Recharger',
            handler: function() {
                this.getForm().load( {
                  url: '/w.php',
                  params: {
                      id_dossier: this.id_dossier
                  },
                  failure:function(form, action) {
                        handleAjaxError(action.response,'Refresh error');
                  }
                });
            },
            scope: this
        },{
            text: 'Sauver',
            handler: function() {
                this.getForm().submit({
                    url: '/ws.php',
                    params: {
                        write: 1
                    },
                    waitTitle: 'Patientez',
                    waitMsg: 'Sauvegarde',
                    success: function (form, action) {
                      var b = Ext.util.JSON.decode(action.response.responseText);
                      if (b.success==true) {
                          if (b.msg) {
                              Ext.MessageBox.alert('Done!', b.msg);
                          }
                          else {
                              Ext.MessageBox.alert('Done!', 'Saved');
                          }
                      }
                    },
                    failure:function(form, action) {
                        handleAjaxError(action.response,'Refresh error');
                    }
                });
            },
            scope: this
        }];
        //this.listeners = {
        //    actioncomplete: handleActionComplete,
        //    load: handleLoad
        //};
        this.on('load', function (a,b,c) {
            console.log(a);
            console.log(b);
            console.log(c);
        });
        this.on('actioncomplete', function (form,action) {
            if (action.type=='load') {
                console.log('actioncomplete => action load');
            }
        });
        this.on('load', function (form,action) {
            if (action.type=='load') {
                console.log('LOAAAAAD');
            }
        });
        DossierPanel.superclass.initComponent.call(this);
        console.log(this.events)
    }
});

仔细观察上面的this.on()代码juste:控制台日志只显示“'actioncomplete => action load'”,而不是'LOAAAAAD'。从我的pov这是不正常的。我错过了什么吗?

非常感谢

1 个答案:

答案 0 :(得分:4)

Ext.form.FormPanel没有load个事件。因此,即使您为load事件定义了一个函数,也不会触发该事件,并且永远不会执行您的函数。

actioncomplete事件是BasicForm的事件,并在操作完成时触发。