I wonder if this is a problem of scope. The thing is that I select an option in a xtype combo (extjs3.4) and that selection at first can be read outside and inside an if section (attached image). Now, when I select another option, that selection is only read outside the if section (ie. it's not read inside it). Is this a normal problem of scope? if so, how could I solve it?

enter image description here

listeners: {
  'select': function(combo, record) {
    var comboLayer = this.getValue();
    var rawLayer = this.getRawValue();
    var loadedLayers = [];
    for(var i = 0; i < mapPanel.map.layers.length; i++) {
    console.log('outsideIf: ' + loadedLayers);
    console.log('outsideIf: ' + rawLayer);
    console.log('outsideIf: ' + comboLayer);
    if (loadedLayers.indexOf(rawLayer) > -1) {
      console.log('insideIf: ' + loadedLayers);
      console.log('insideIf: ' + rawLayer);
      console.log('insideIf: ' + comboLayer);
      newUrl = '/pg?layers=' + comboLayer;
      protocol.options.url = newUrl;
  • 1
    Are you sure that the combo value (rawLayer) is within the loadedLayers array on the second selection? If the condition fails, you don't see the insideIf messages. Can you try with an additional else just to make sure? – jgrocha Dec 17 '14 at 0:21
  • @jgrocha using else I found the solution, it was like you suggested, thanks for that! – Gery Dec 17 '14 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.