重置ExtJS中的事件处理程序

时间:2010-10-12 20:12:07

标签: extjs

我有一个有多个记录的页面。每个记录都有一个按钮,用于打开一个对话框来创建名称。然后,该名称在数据库中创建相关记录并更新源记录。

实例化了一个对话框,我想显示对话框,获取结果并将其返回到正确的记录。

下面的代码只运行一次,但第二次运行不起作用。我可以看到单击“创建”按钮,但事件未被捕获。

非常感谢你的帮助。

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());
};
};

1 个答案:

答案 0 :(得分:0)

在ExtJS中,当您拥有属于父级的组件时。我建议使用itemID,否则会减少在Web应用程序中重用组件的能力,因为id的行为与单例类似。同样在动作上,你有{single:true},这将在第一次触发后删除侦听器。如果你删除它,它可以解决你的问题