我正在使用jquery和这个插件。 This是我目前所拥有的(底层的实际问题):
到目前为止,我有以下代码:
var properties = [];
jQuery.each(json['properties'],function(k,v){
properties.push({
name:v.name,
status:v.status,
color:v.color,
size:v.size,
price:v.price
});
});
console.log(properties);
它返回的getJson:
{
"land": {
"Long Land": {
"path": "M541.421,195.072 156.67,423.574 7.16,321.971 428.509,14.837 639.505,78.824 715.519,62.551 696.101,102.448 484.892,100.685 238.629,265.688 298.41,338.024 540.763,194.308 526.509,170.217 747.15,108.014 780.865,164.098 611.146,314.125",
"name": "Long Land"
}
},
"properties": {
"unit 1": {
"path": "M541.421,195.072 156.67,423.574 428.509,14.837 639.505",
"name": "unit 1",
"status": "Available",
"color": "#244df0",
"size": "3200",
"price": "300 000"
}
}
}
然后对于console.log(属性)我得到一个包含以下内容的对象:
color "#244df0"
name "unit 1"
price "300 000"
size "3200"
status "Available"
然后我初始化jvectormap:
//START JVECTORMAP
jQuery('#twinvalley-map').vectorMap({
map: 'twin_valley',
normalizeFunction: 'polynomial',
backgroundColor: false,
onRegionClick:function (event, code, region){
console.log(code);
}
});
//START JVECTORMAP
然后最后为onRegionClick console.log()我得到的名称与之前的两个日志相同..'unit 1'。
所以现在我的问题是,我如何获得区域点击的其余数据?数据我的意思是:
color "#244df0"
name "unit 1"
price "300 000"
size "3200"
status "Available"
任何帮助都非常赞赏。
答案 0 :(得分:1)
尝试使用代码作为索引:
onRegionClick:function (event, code, region){
console.log('Name: ' + json['properties'][code]['name'] + ', color: ' + json['properties'][code]['color']);
}