如何在 JavaScript 中添加第二个属性?

How do I add a second attribute in JavaScript?

我目前正在使用 jvectormap。每个县都有一个数据代码(例如:48201)。这是我到目前为止已经着色的县的代码...

jvm.Map.maps = {};
jvm.Map.defaultParams = {
  map: 'us_lcc_en',series: {
        regions: [{
            values: {

/* -------------- 活跃特许经营 -------------- */

                '42029':'#eb2e4d',
                '42091':'#eb2e4d',
                '42101':'#eb2e4d',
                '42045':'#eb2e4d',
                '42017':'#eb2e4d',
                '42077':'#eb2e4d',
                '42095':'#eb2e4d',
                '48085':'#eb2e4d',
                '48113':'#eb2e4d',
                '48439':'#eb2e4d',
                '48121':'#eb2e4d',

/* -------------- 可用特许经营权 -------------- */

                '42129':'#5d9eec',
                '42007':'#5d9eec',
                '42125':'#5d9eec',
                '42019':'#5d9eec',
                '42003':'#5d9eec',
                '13067':'#5d9eec',
                '13121':'#5d9eec',
                '13057':'#5d9eec',
                '13135':'#5d9eec',
                '13089':'#5d9eec',
                '13063':'#5d9eec',
                '13151':'#5d9eec',
                '13297':'#5d9eec',
                '13117':'#5d9eec',
                '48339':'#5d9eec',
                '48201':'#5d9eec',
                '48157':'#5d9eec',
                '48167':'#5d9eec',
                '48039':'#5d9eec',
                '48029':'#5d9eec',
                '48187':'#5d9eec',
                '48091':'#5d9eec',
                '04013':'#5d9eec',
                '09003':'#5d9eec',
                '09013':'#5d9eec',
                '09001':'#5d9eec',
                '09009':'#5d9eec',
                '09007':'#5d9eec',
                '09005':'#5d9eec',

/* -------------- 待定特许经营权 -------------- */

                '48491':'#83a85d',
                '48453':'#83a85d',
                '48209':'#83a85d',

            },

            attribute:'fill',
            "stroke-width": 4

        }]

    },
  backgroundColor: '#ffffff',
  zoomButtons: true,
  zoomOnScroll: false,
  panOnDrag: true,
  zoomMax: 8,
  zoomMin: 1,
  zoomStep: 1.6,
  zoomAnimate: true,
  regionsSelectable: false,
  markersSelectable: false,
  bindTouchEvents: true,
  regionStyle: {
    initial: {
      fill: 'rgb(204, 204, 204)',
      "fill-opacity": 1,
      stroke: 'rgb(204, 204, 204)',
      "stroke-width": 0,
      "stroke-opacity": 1,
    },
    hover: {
      "fill-opacity": 0.7,
      cursor: 'pointer'
    },
    selected: {
      fill: 'yellow'
    },
    selectedHover: {
    }
  },
  regionLabelStyle: {
    initial: {
      'font-family': 'Verdana',
      'font-size': '12',
      'font-weight': 'bold',
      cursor: 'default',
      fill: 'black',
    },
    hover: {
      cursor: 'pointer'
    }
  },
  markerStyle: {
    initial: {
      fill: 'grey',
      stroke: '#505050',
      "fill-opacity": 1,
      "stroke-width": 1,
      "stroke-opacity": 1,
      r: 5
    },
    hover: {
      stroke: 'black',
      "stroke-width": 2,
      cursor: 'pointer'
    },
    selected: {
      fill: 'blue'
    },
    selectedHover: {
    }
  },
  markerLabelStyle: {
    initial: {
      'font-family': 'Verdana',
      'font-size': '12',
      'font-weight': 'bold',
      cursor: 'default',
      fill: 'black'
    },
    hover: {
      cursor: 'pointer'
    }
  }
};
jvm.Map.apiEvents = {
  onRegionTipShow: 'regionTipShow',
  onRegionOver: 'regionOver',
  onRegionOut: 'regionOut',
  onRegionClick: 'regionClick',
  onRegionSelected: 'regionSelected',
  onMarkerTipShow: 'markerTipShow',
  onMarkerOver: 'markerOver',
  onMarkerOut: 'markerOut',
  onMarkerClick: 'markerClick',
  onMarkerSelected: 'markerSelected',
  onViewportChange: 'viewportChange'
};

如您在底部所见...属性设置为 'fill'。我也想添加'stroke'。我该如何添加第二个属性?

javaScript 对象中的属性用逗号分隔。假设你想添加一个 stroke-width 属性:

在这种情况下,您可以将靠近底部的尾端更改为如下所示:

            '48491':'#83a85d',
            '48453':'#83a85d',
            '48209':'#83a85d',

        },
        attribute: 'fill',
        stroke-width: 4
    }]
},

这应该会让你开心。不过,顺便说一句,stroke-width 实际上是 'regions' 的第三个属性:您会注意到值是以 "values: {...}," 的形式编写的——它也是一个属性!