Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXT JS - adding a listener on any element added to a container

Tags:

extjs

HI, I have a ExtJS parent 'container' type, whereas i need to add a 'contextmenu' listener to any element that is added to this parent container, via Drag/Drop. Can someone guide me as to the best way to do this?

I have tried this below but can't get the function to fire.

myContainer.on('added', function(obj1,obj2,index){
   alert('added');
});

this may not be the 'best practice' to do it this way anyway...? thanks for the help !

like image 752
29er Avatar asked Jan 20 '11 20:01

29er


1 Answers

You're using the wrong event... The added event gets fired when (using your example) myContainer is added to some other container. What you'll need is the add event that fires, when an item is added to myContainer:

myContainer.on('add', function(container, component, index) {
    component.on('contextmenu', function() {
    });
});
like image 126
Stefan Gehrig Avatar answered Nov 15 '22 03:11

Stefan Gehrig