1

Anyone used http://github.com/manifestinteractive/jqvmap/ ?

These work:

$('#map').vectorMap('set', 'colors', { us: '#8EE5EE' });
$('#map').vectorMap('set', 'colors', { 'us': '#8EE5EE' });

But, this doesnt:

country_name = 'us';
$('#map').vectorMap('set', 'colors', { country_name: '#8EE5EE' });

Anyone know why?

Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215

1 Answers1

7

Because that's not how object literals work. The key part in the key-value pair is interpreted as a literal string. You need to use bracket-syntax to have a dynamic key name. It's that or eval, and you don't want to use eval.

var country_colors = {};
var country_name = 'us';

country_colors[country_name] = '#8EE5EE';

$('#map').vectorMap('set', 'colors', country_colors);
Michael Morgan
  • 816
  • 5
  • 6
  • Michael - this is the closest I've been all day, so thanks! Wondering if you could show an example given a comma separated list of states that will all be set to the same color? The list is dynamic and stored in a js variable currently. An example in the variable might be (tx,co,in,id) – hardba11 Sep 10 '12 at 20:54