for (var i = 0; i < pois.length; i++) {
pois[i].marker.addEventListener('dblclick', function (data) {
var infoWindow = new BMap.InfoWindow(pois[i].address, opts);
map.openInfoWindow(infoWindow, map.getCenter());
})
}
this is my code.
obviously there is an error at here
new BMap.InfoWindow(pois[i].address, opts);
how can I use pois[i].address in pois[i].marker listener function ?
Answer
for (var i = 0; i < pois.length; i++) {
setupEventListener(pois[i]);
}
function setupEventListener(obj) {
var address = pois[i].address;
obj.marker.addEventListener('dblclick', function (data) {
var infoWindow = new BMap.InfoWindow(address, opts);
map.openInfoWindow(infoWindow, map.getCenter());
});
}
No comments:
Post a Comment