Results 1 to 4 of 4

Thread: scope of handler

  1. #1
    Ext User
    Join Date
    Jun 2010
    Posts
    3
    Vote Rating
    0
      0  

    Default scope of handler

    I have a button nested 2 levels deep and am trying to call a function on the top level, but can't get it to work. I set the scope to 'parent' and tried 'parent.parent'. See code below, the handler is "handler: doAlert"

    var tabpanel = new Ext.TabPanel({
    tabBar: {
    dock: 'bottom',
    layout: {
    pack: 'center'
    }
    },
    fullscreen: true,
    ui: 'light',
    activeItem: 0,
    animation: {
    type: 'flip',
    cover: true
    },
    items: [{
    title: 'Map',
    cls: 'card4',
    iconCls: 'settings',
    xtype: 'map',
    items:[mapdemo],

    }, {
    title: 'Search',
    cls: 'card1',
    iconCls: 'user',
    items: [{
    xtype: 'textfield',
    name : 'address',
    label: 'Address'
    }],
    dockedItems: [
    {
    xtype: 'toolbar',
    dock: 'bottom',
    items: [
    {
    text: 'Search',
    ui: 'round',
    handler: doAlert,
    scope:parent

    }
    ]
    }
    ]

    }]

    });
    //
    var doAlert = function(btn, event){
    alert('DO IT')
    }

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,583
    Vote Rating
    873
      0  

    Default

    You can't do that, "parent" isn't a valid scope.

    The problem you're facing is that none of the objects are actually created, the whole RHS is evaluated before the tabPanel variable is assigned. The best way would be to use an id to grab the component.
    Evan Trimboli
    Twitter - @evantrimboli

  3. #3
    Ext User
    Join Date
    Jun 2010
    Posts
    3
    Vote Rating
    0
      0  

    Default

    Thank you. Could you let me know how to set and retrieve the id of a component? or point me to this documentation?
    thanks!

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    11
      0  

    Default

    Every component has an id config option, and you can retrieve a component using Ext.getCmp. You might however want to break up your source code and define individual instances to variables so you can easily reference them.

Similar Threads

  1. Scope for Direct handler
    By makcs in forum Ext.Direct
    Replies: 2
    Last Post: 27 Dec 2009, 8:54 AM
  2. Handler scope
    By bkraut in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 7 Jul 2009, 1:09 AM
  3. Action handler scope
    By john.brown in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 18 Sep 2008, 12:41 PM
  4. Scope Within Tool Handler???
    By arth in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 10 Sep 2008, 11:16 AM

Posting Permissions

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