Prabath Yapa
Prabath Yapa

Reputation: 1229

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!

Upvotes: 5

Views: 8507

Answers (1)

user123444555621
user123444555621

Reputation: 153234

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.

Upvotes: 12

Related Questions