独角兽企业重金招聘Python工程师标准>>>
这个东西其实很简单,解决思路就是创建一个外部函数,将要使用的参数传递过去,这样所有的点击事件就都能持久存在。
var data_info =new Array();var optss = new Array();var markers = new Array();var contents = new Array();var points = new Array();for(var i=0;response.data.length>i;i++){var data_tow=[]; data_tow.push(response.data[i].latitude,response.data[i].longitude,"时间:"+response.data[i].creationTime);data_info.push(data_tow);optss.push({width : 25,// 信息窗口宽度height: 30,// 信息窗口高度title : "设备编号:"+response.data[i].facilityId , // 信息窗口标题});contents.push(data_info[i][2]);points.push(new BMap.Point(data_info[i][0],data_info[i][1]));markers.push(new BMap.Marker(points[i])); map.addOverlay(markers[i]);var infoWindow = new BMap.InfoWindow(contents[i],optss[i]); // 创建信息窗口对象biaozhu(infoWindow,points[i]);}function biaozhu(infoWindow,point){markers[i].addEventListener('click', function(){this.openInfoWindow(infoWindow,point);});}console.log(response);}).catch(error => {console.log(error);})
我的思路是将各种我需要用到的数据(marker,point等等需要使用多个的数据)都用一个数组保存起来方便使用