Data assembly - which is the object key: value, value of which is in the form of an array, such as {key: [aa, bb], key: [cc, dd]}

After the combination of the object which is key: value, value of which is in the form of an array of {key: [aa, bb], key: [cc, dd]}
var chinaGeoCoordMap = {
'Wuxi': [121.4648, 31.2891],
'Langfang City': [119.5313, 29.8773],
"Jinhua": [118.8062, 31.9208],
 
The second argument passed as an array of
this.add(this.centerdata[i].city,[this.centerdata[i].x,this.centerdata[i].y])
 data: {
              centerdata:[
                 {"city": "无锡市","clusterID": 1, "x": 120.7485913653,"y": 31.809979797058332},
                 {"city": "廊坊市","clusterID": 2,"x": 130.7485913653,"y": 39.215436433250005},
                 {"city": "金华市","clusterID": 3,"x": 140.7485913653,"y": 29.190387826775}
              ]
            },
  created() {
            for(var i=0;i<this.centerdata.length;i++){
              this.add(this.centerdata[i].city,[this.centerdata[i].x,this.centerdata[i].y]);//传参是重点
            }
          },
          
          methods: {
              add(key,value){
                let keyValue={}
                keyValue[key]=value;
                console.log(keyValue)
               }
          },


Guess you like

Origin www.cnblogs.com/IwishIcould/p/11355548.html