简体   繁体   中英

Compare getValue with map.layers[i].name

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,

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

@Guilherme Lopes谢谢您,但是解决方案是这样: mapPanel.map.layers.length而不是mapPanel.map.length

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM