将变量传递到数组 jVectorMap JavaScript

Pass variable into array jVectorMap JavaScript

谁能给我解释一下如何在此处传递变量: 系列:{地区:[{值:{变量:'#B8E186',}}]},

评论的部分是我到目前为止尝试过的。那里的语法是这样的 {SE:'#000FFF',}

            //var myArray = [];
            //myArray.push({ 'NO': '#000FFF' });
            //var a = [], b = parsedData.Item1, c= '#000FFF';
            //a.push('b', 'c');
            //var cdata = {
                map: 'world_mill',
                scaleColors: ['#C8E111', '#007FFF'],
                normalizeFunction: 'polynomial',
                hoverOpacity: 0.7,
                hoverColor: false,
                markerStyle: {
                    initial: {
                        fill: '#F8E111',
                        stroke: '#383f47'
                    }
                },
                series: {
                    regions: [{
                        values:
                        {
                        }
                    }]
                },
                regionStyle: {
                    initial: {
                        fill: '#B8E186'
                    }
                },
                backgroundColor: '#FFFFF',
                //markers: [
                //    { latLng: [67.16, 14.24], name: 'Norway' },
                //]
                //});
            //};
            //jQuery.each(cdata.mapData.paths, function() {
               // var continentCodes = {};
               // continentCodes['NO'] = "#128da7";
                //cdata.series.regions[0].setValues(continentCodes);
            });
            //var mapObject = $('#world-map').vectorMap('camel', 'mapObject');
            //mapObject.series.regions[0].setValues(parsedData.Item1) =             '#000FFF';
            //});
         });

假设系列有多个区域,区域的值有多个变量值

您将需要两个 for 循环

var series = {};

for (i = 0; i < regions.length; i++) { 
{
var regions = [];
var values = {};
for (j = 0; j < ValuesInRegion.length; j++) { 
{
values[ValuesInRegion[j]['key']] = ValuesInRegion[j]['value'];
}
regions.push(values);
}
series['regions'] = regions;

终于

cdata.series = series;