Results 1 to 7 of 7

Thread: How to listen to events thrown from other components?

  1. #1
    Ext JS Premium Member
    Join Date
    May 2008
    Location
    Austin, TX
    Posts
    55

    Default How to listen to events thrown from other components?

    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
    Code:
    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!!!
    Thanks,

    MB

  2. #2
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    MB, are you familiar w/ the "this" keyword?

  3. #3

    Default

    try set 'id' for each reference component, then u may refer to it when needed. may be work... sorry if wrong.

  4. #4
    Ext JS Premium Member
    Join Date
    May 2008
    Location
    Austin, TX
    Posts
    55

    Default

    Quote Originally Posted by [email protected] View Post
    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?
    Thanks,

    MB

  5. #5

    Default

    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.

  6. #6
    Sencha User
    Join Date
    Oct 2009
    Location
    Romania
    Posts
    56

    Default The this keyword

    Quote Originally Posted by [email protected] View Post
    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:

    Code:
    this.on('eventname', function(){
       //this is the same this as above :)
       this.doSomething();
    }, this /*scope=this*/ )
    I blog about JavaScript and Ext on http://jslog.com. Contact me for ExtJs support. Follow me @extjslog.

  7. #7
    Ext JS Premium Member
    Join Date
    May 2008
    Location
    Austin, TX
    Posts
    55

    Default

    Quote Originally Posted by Mike Robinson View Post
    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.
    Thanks,

    MB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •