[英]Google Maps : google.maps.event.addListener
i have shapes and i draw it in maps : 我有形状,并在地图上绘制:
shapes; //array of shapes, i draw it from string that i take from db
for (var i = shapes.length - 1; i >= 0; i--) {
google.maps.event.addListener(shapes[i], 'click', function() {
myFunc(shapes[i]); //function to edit shapes[i]
});
};
when i do this : 1. eg i have shapes length = 5; 当我这样做时:1.例如,我的形状长度= 5; 2. i click in 1 of the shape but myFunc always called with i=5 so myFunc always call shapes[5]
2.我单击形状的1,但myFunc总是以i = 5调用,因此myFunc总是调用shape [5]
i already try : Passing a pointer to objects method safely to google.maps.event.addListener 我已经尝试过: 将指向对象方法的指针安全地传递给google.maps.event.addListener
but still fail, can someone give me advice? 但仍然失败,有人可以给我建议吗?
shapes; 形状; //array of shapes, i draw it from string that i take from db
//形状数组,我是从数据库中提取的字符串绘制的
for (var i = shapes.length - 1; i >= 0; i--) {
(function (i) {
google.maps.event.addListener(shapes[i], 'click', function() {
myFunc(shapes[i]); //function to edit shapes[i]
});
})(i);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.