创建了一个window,给window绑定了beforeclose事件,然后调用用removeListener方法,但是无效无法移除beforeclose事件
代码如下:  win = new Ext.Window({
id: 'test',
footer : false,
width: 640,
height: 480,
iconCls: 'accordion'
}); win.on('beforeclose', function() {alert(1);}, this);
win.removeListener('beforeclose');
win.show();
当关闭窗体时,系统仍然会弹出对话框alert(1);,请问如何移除掉'beforeclose'事件?

解决方案 »

  1.   


    win = new Ext.Window({
            id: 'test',
            footer : false,
            width: 640,
            height: 480,
            iconCls: 'accordion'
        });
        var f=function() {alert(1);};
        win.on('beforeclose', f, this);
        win.removeListener('beforeclose',f,this);
        win.show();
    removeListener( String eventName, Function handler, [Object scope] ) : void
    Removes an event handler.
    Removes an event handler.
    Parameters:
    eventName : String
    The type of event the handler was associated with.
    handler : Function
    The handler to remove. This must be a reference to the function passed into the addListener call.scope : Object
    (optional) The scope originally specified for the handler.
    Returns:
    void
      

  2.   

    你在绑定的时候是绑定的一个匿名函数,匿名的你又怎么删除呢?所以你要在外面单独新建个函数,在绑定和删除就没问题了
    win = new Ext.Window({
            id: 'test',
            footer : false,
            width: 640,
            height: 480,
            iconCls: 'accordion'
        });
        aa=function() {alert(1);}
        win.on('beforeclose',aa , this);
        win.removeListener('beforeclose',aa , this);
        win.show();
      

  3.   

    [Quote=引用 3 楼 antony1029 的回复:]
    引用 2 楼 sohi