Search code examples
extjsextjs4dom-events

ExtJS remove listener


I'm having difficulty getting this to work:

var fn = function(){};

Ext.select('ul > li').on('click',fn);
// works

Ext.select('ul > li').un('click',fn);
//doesn't work

'un'/'removeListener' does not work. Appreciate any help!


Solution

  • By default, Ext.select creates a flyweight object, which does not remember event listeners. Thus, they cannot be removed later.

    You need to create real Ext.Elements by setting the second parameter to true:

    var fn = function(){};
    
    Ext.select('ul > li', true).on('click',fn);
    
    Ext.select('ul > li', true).un('click',fn);
    

    Unfortunately, the docs are not very clear about this.