javascript and extJs - scope question

Posted by ben on Stack Overflow See other posts from Stack Overflow or by ben
Published on 2010-04-06T12:01:12Z Indexed on 2010/04/06 12:03 UTC
Read the original article Hit count: 262

Filed under:

Hi guys, I got a little scope related problem with some js code, maybe somebody can explain to me what I'm making wrong:

I'm using extJs and got this snippet:

Ext.onReady(function(){

 // Form for filter selection
 var formFilter = new Ext.FormPanel({
  // ...
        items: [
   cbGroup = new Ext.form.ComboBox({    
                fieldLabel: 'Group',
    store: dsGroups,
    displayField: 'name',
    valueField: 'number',
    emptyText : '- Please choose a group -',
    listeners:{
      'select': function() {
       alert(cbGroup.selectedIndex +' '+this.selectedIndex);
      }
     }
    })
   ]
    }); 
});

The problem: When I access the combobox over 'this' within the listener function, I get the correct result for the selectIndex property. When I access the combobox over it's var name, I allways get the result '-1'. Thank a lot for your help!

© Stack Overflow or respective owner

Related posts about JavaScript