Compare getValue with map.layers[i].name

63 Views Asked by At

As part of a xtype combo, I would like to know if the layer I choose in my simple data store (represented by this.getValue()) is present in the map layers. So if it does, A should occur, and B if it does not. The problem is that myLayer variable seems to be unrecognized, even though Opera Dragonify throws no error at all. Where would be the error?

listeners: {
  'select': function(combo, record) {
    for(var i = 0; i < mapPanel.map.length; i++) {
      var myLayer = mapPanel.map.layers[i].name;
      if (myLayer == this.getValue()) {
        // do A here...
      } else {
        // do B here...
      }
    }
  }
}

Thanks for any pointers,

2

There are 2 best solutions below

0
Gery On BEST ANSWER

@Guilherme Lopes Thanks for that, but the solution was this: mapPanel.map.layers.length instead of mapPanel.map.length.

0
Guilherme Lopes On

I think the problem is that you are using this.getValue() instead of using combo.getValue(). I don't know how your app is set but it's usually a better idea to use the first parameter of your listener instead of the keywork this in order to avoid scope issues.

Hope this helps