2011-03-24 87 views
0

这是我的ExtJs组件。 一切正常完美......差不多所有东西都是。 我只是不明白为什么this.on('load', function (form,action) {})不叫而对于this.on('actioncomplete', function (form,action) {});相同的声明被称为:ExtJS和事件监听器:'load'未被调用。怎么会?

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()代码上面探微:控制台日志只显示“'actioncomplete = >行动负载'“,而不是'LOAAAAAD'。从我的pov这是不正常的。我错过了什么吗?

非常感谢您

回答

4

Ext.form.FormPanel没有load事件。所以,即使你为load事件定义了一个函数,事件也不会被触发,你的函数也不会被执行。

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

+0

如果是这样,我不明白为什么有一个事件与action.type =='加载'。我认为(我认为这很明显):“如果在全局事件处理程序(”actioncomplete“)中有一个名为”load“的事件,这意味着有一个实际的事件”加载“。您认为什么? – 2011-03-24 09:22:00

+0

action.type是指加载或提交表单的操作,它与组件事件无关 – 2011-03-24 09:46:47

+0

非常感谢,我的英语有点完美,所以我经常感到困惑在行动和事件之间。 – 2011-03-24 13:56:58