我想以变量的形式输入国家名,但我不能。
var interval_1=window.setInterval(function() {
var name = "USA";
map.updateChoropleth({
name : colors(Math.random() * 10),
});
}, 2000);发布于 2015-03-25 12:00:23
您想要的是在JavaScript对象文本中使用一个变量作为键。这里已经回答了这个问题:Using a variable for a key in a JavaScript object literal
这将给出您期望的结果:
var interval_1=window.setInterval(function() {
var name = "USA";
var country = {}
country[name] = colors(Math.random() * 10)
map.updateChoropleth(country);
}, 2000);https://stackoverflow.com/questions/29254740
复制相似问题