I'm using jvectormap and I want to unselect a state when I select another, but I have this error
TypeError: this[e][n] is undefined.
This is part of my code:
Selector2 = {
colorBlank : 'white',
selectedColor : '#0D88BC',
oldcode: '',
disable:function(old_code,objMap){
old_code = String(old_code);
objMap.setSelectedRegions({old_code:false});
},
select:function(id){
var mapObj = jQuery('#states-area').vectorMap('get', 'mapObject');
if(this.oldcode.length != 0){
_code = this.oldcode;
this.disable(_code,mapObj);
}
this.oldcode = id;
stateCode = id;
},
The variable id
is the state's key, and in this line objMap.setSelectedRegions({old_code:false})
appears the error.
What's wrong? help me please.
In this line:
objMap.setSelectedRegions({old_code:false});
Here you set the selection state of the region named "old_code"
, not the one named after the value in the old_code
variable. Here are some fixes:
// ES6
objMap.setSelectedRegions({[old_code]:false});
// or ES5
var temp = {};
temp[old_code] = false;
objMap.setSelectedRegions(temp);