Results 1 to 6 of 6

Thread: [SOLVED] Custom listeners

  1. #1
    Sencha User
    Join Date
    May 2010
    Location
    Hamburg, Germany
    Posts
    97

    Default [SOLVED] Custom listeners

    Howdy,

    I use this simple function for my change listener:

    Code:
    listeners: {
      change: function(obj) {
        tmpProp[obj.id] = this.getValue();
        for (var record in tmpProp) {
          console.log(record + ': ' + tmpProp[record]);
        }
      }
    }
    tmpProp is a global Object() instance. I need this code dozens of times so I try to get the code out of my listener: {change: {}} block to reuse it everywhere I need it. I'm using an application class like described in http://www.sencha.com/learn/Tutorial..._for_Beginners but don't get the code running. Anyone has a hint how to define an external function for this listener?
    Cheerio,

    Chris

  2. #2
    Sencha User
    Join Date
    Jun 2009
    Location
    Colorado
    Posts
    51

    Default

    What is 'this' referencing when calling this.getValue()?

    If you define that function externally:

    Code:
    function changeListener (obj) {     
      tmpProp[obj.id] = this.getValue();     
      for (var record in tmpProp) {       
        console.log(record + ': ' + tmpProp[record]);
    }
    
    ...
    
    listeners: {   
      change: changeListener.createDelegate(this)
    }
    May get you what you are looking for..

  3. #3
    Sencha User
    Join Date
    May 2010
    Location
    Hamburg, Germany
    Posts
    97

    Default

    Many thanks for the prompt reply Keylan.

    It seems, I'm in newbie trouble ;-) I wanna define changeListener in global context, so my main JS consists of:

    Code:
    Ext.BLANK_IMAGE_URL = '/ext/resources/images/default/s.gif';
    Ext.ns('App', 'App.widget', 'App.store', 'App.var');
    
    App.main = function() {
    
      // private variables
    
      // private functions
    
      // public space
      return {
    
        // public properties
    
        // public methods
        init: function() {
          App.var.tmpProperty = new Object();
          function changeListener (obj) {
            App.var.tmpProperty[obj.id] = this.getValue();
            for (var record in App.var.tmpProperty) {
              console.log(record + ': ' + App.var.tmpProperty[record]);
            }
          };
        }
      };
    }();
    I followed the beginners howto: http://www.sencha.com/learn/Tutorial..._for_Beginners

    I'm initializing the app by

    Code:
    Ext.onReady(App.main.init, App.main)
    ... so all should work fine. My listener I'm calling

    Code:
    listeners: { change: changeListener.createDelegate(this) }
    and get an error: "changeListener is not defined"

    Hm, it seems the changeListener function is not visible by my further code, but can't see why ...
    Cheerio,

    Chris

  4. #4
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,676

    Default

    it's not global.

    Change it to

    Code:
    App.changeListener = function() {...}
    
    ...
    
    listeners: { change: App.changeListener.createDelegate(this) }
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  5. #5
    Sencha User
    Join Date
    May 2010
    Location
    Hamburg, Germany
    Posts
    97

    Default

    Great, all works fine now 8-) Many, many thx ...
    Cheerio,

    Chris

  6. #6
    Sencha User
    Join Date
    Jun 2009
    Location
    Colorado
    Posts
    51

    Default

    Hurray teamwork.

Similar Threads

  1. Ext.Event static listeners[] slows down listeners removal
    By gbulfon in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 31 Aug 2009, 7:51 AM
  2. Custom class v. Extension, custom events
    By repata in forum Ext 2.x: Help & Discussion
    Replies: 15
    Last Post: 17 Dec 2008, 6:11 PM
  3. Inline event listeners - custom args
    By cafebabe in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 29 Jan 2008, 12:41 PM

Posting Permissions

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