PDA

View Full Version : How to listen to events thrown from other components?



blancomario
12 May 2010, 11:40 AM
I am trying to setup a combobox and a treepanel to talk to each other via events. When a selection is made in the combobox the combobox will throw and event than the treepanel will listen to this event a do so stuff. However, I just can't get it to work. What am I missing?

Below is a small piece of code of that illustrates what I am trying to do


myCombo = Ext.extend(Ext.form.ComboBox({

initComponent: function(){
myCombo.superclass.initComponent.apply(this,arguments);
this.addEvents("listchanged");
this.on("select", function(combo, record, index){
this.fireEvent("listchanged", record);
}
}
});

myTree = Ext.extend(Ext.tree.TreePanel({
initComponent: function(){
myTree.superclass.initComponent.apply(this,arguments);
this.on("listchanged", function(record){
//do some stuff
});
}
});
Thanks!!!

16 May 2010, 8:08 AM
MB, are you familiar w/ the "this" keyword?

norizam61
17 May 2010, 2:58 AM
try set 'id' for each reference component, then u may refer to it when needed. may be work... sorry if wrong.

blancomario
1 Jun 2010, 7:29 AM
MB, are you familiar w/ the "this" keyword?

I think I am :). In the code I posted, I don't see where I am using the "this" keyword wrong. Where do you see I am not using it correctly?

Mike Robinson
1 Jun 2010, 7:48 AM
Early on, I discovered Saki's msgbus plugin, which is a very well-written and generally applicable tool for letting disparate pieces of an application "talk among themselves." Components publish events, and they can subscribe to the things they want to listen to ... even using a regular-expression to limit their attention to only those events that they actually care about.

Go here: http://examples.extjs.eu/?ex=compcomm

It's quite a small piece of code, and it works extremely well.

radubrehar
1 Jun 2010, 8:07 AM
MB, are you familiar w/ the "this" keyword?

I think jgarcia refers to using the this keyword in the wrong context.
You should do something like:


this.on('eventname', function(){
//this is the same this as above :)
this.doSomething();
}, this /*scope=this*/ )

blancomario
1 Jun 2010, 8:16 AM
Early on, I discovered Saki's msgbus plugin, which is a very well-written and generally applicable tool for letting disparate pieces of an application "talk among themselves." Components publish events, and they can subscribe to the things they want to listen to ... even using a regular-expression to limit their attention to only those events that they actually care about.

Go here: http://examples.extjs.eu/?ex=compcomm

Mike,

Thanks. I seems simple enough and will give it a try.