我正在使用jVectormap插件。
我有一系列国家代码,currentCodes
我在开始时声明。在页面的下方,我正在使用插件的内置“系列”功能,该功能使我能够为某些国家/地区提供不同的默认颜色。在values: { }
下面series: { }
,我再次写出每个值currentCodes
并将它们设置为系列中的 1。这工作正常。
jQuery.noConflict();
jQuery(function(){
var $ = jQuery;
var currentCodes = ["GG","IE","IM","JE","_22","_25","_23","_24"];
$('#map').vectorMap({
map: 'world_mill_en',
backgroundColor: '#b0e0fb',
……
series: {
regions: [{
scale: ['#008d48'],
normalizeFunction: 'polynomial',
values: {
"GG": 1,
"IE": 1,
"IM": 1,
"JE": 1,
"_22": 1,
"_25": 1,
"_23": 1,
"_24": 1
}
}]
}
……
});
但我想要的是一种将currentCodes
数组中的任何值自动设置为 1 的方法。我知道在这里使用 for 循环是完全错误的语法,但也许它会证明我需要什么:
jQuery.noConflict();
jQuery(function(){
var $ = jQuery;
var currentCodes = ["GG","IE","IM","JE","_22","_25","_23","_24"];
$('#map').vectorMap({
map: 'world_mill_en',
backgroundColor: '#b0e0fb',
……
series: {
regions: [{
scale: ['#008d48'],
normalizeFunction: 'polynomial',
values: {
// set each value in currentCodes array so it is 1
var i;
for (i = 0; i < currentCodes.length; i++) {
currentCodes[i]: 1,
}
}
}]
}
……
});
谢谢,任何帮助将不胜感激。我对对象和属性语法不是很有经验,我相信这是这里使用的...