2010-10-12 41 views
0

我有一個有多個記錄的頁面。每個記錄都有一個按鈕來打開一個對話框來創建一個名稱。該名稱然後在數據庫中創建相關記錄並更新源記錄。在ExtJS中重置事件處理程序

有一個實例化的單個對話框,我想顯示對話框,獲取結果並將其返回給正確的記錄。

下面的代碼工作一次,但第二次不工作。我可以看到Create按鈕被點擊,但事件沒有被捕獲。

非常感謝您的幫助。

TrailNamePresenter.prototype.onCreateTrailClick = function (trailSegment, combo, personalRouteId) { 
if (!this.createTrailWindow) { 
    this.createTrailWindowPanel = new CreateTrailFormPanel(); 
    this.createTrailWindow = new Ext.Window({ 
     title: 'Create Trail', 
     closable: true, 
     closeAction: 'hide', 
     plain: true, 
     items: [this.createTrailWindowPanel], 
     id: 'createtrailwindow' 
    }); 
} 


this.createTrailWindowPanel.on('createTrail', this.getCreateTrailHandler(personalRouteId, trailSegment, combo), null, {single:true}); 

this.createTrailWindow.show(); 
}; 

TrailNamePresenter.prototype.getCreateTrailHandler = function(personalRouteId, trailSegment, currentTrailCombo) { 
var thisPersonalRouteId = personalRouteId; 
var thisPresenter = this; 
var thisCurrentTrailCombo = currentTrailCombo; 
var thisTrailSegment = trailSegment; 
return function(newTrailName) { 
    thisPresenter.mapEditorService.createPersonalTrail(newTrailName, thisPersonalRouteId, thisPresenter.getCreateTrailServiceHandler(thisCurrentTrailCombo, thisTrailSegment)); 
}; 
}; 

CreateTrailFormPanel = Ext.extend(Ext.form.FormPanel, { 
initComponent: function() { 
    Ext.apply(this, { 
     id: 'createtrailpanel', 
     width: 500, 
     frame: true, 
     bodyStyle: 'padding: 10px 10px 0 10px;', 
     labelWidth: 50, 
     defaults: { 
      anchor: '95%', 
      msgTarget: 'side' 
     }, 
     items: [ 
      { 
       id: 'crt_trailnamefield', 
       xtype: 'textfield', 
       fieldLabel: 'Trail Name' 
      } 
     ], 
     buttons: [{ 
      text: 'Create', 
      handler: this.getCreateClickHandler() 
     },{ 
      text: 'Cancel', 
      handler: function(b, e){ 
       Ext.getCmp('createtrailwindow').hide(); 
      } 
     }] 
    }); 

    this.addEvents('createTrail'); 

    CreateTrailFormPanel.superclass.initComponent.apply(this, new Array()); 

} 
}); 

CreateTrailFormPanel.prototype.getCreateClickHandler = function() { 
var thisPanel = this; 
return function() { 
    var trailNameField = Ext.getCmp('crt_trailnamefield'); 
    alert('click'); 
    thisPanel.fireEvent('createTrail', trailNameField.getValue()); 
}; 
}; 

回答

0

在ExtJS中,當您擁有屬於父項的組件時。我會建議使用itemID,否則跨組件重用的能力會降低,因爲id的行爲與單例類似。同樣在動作上,你有{single:true},它將在第一次觸發後刪除監聽器。如果你刪除它,它可能會解決您的問題