【发布时间】:2012-11-06 23:03:40
【问题描述】:
您好,我正在使用下面的代码来填充标记,并且我使用了一个函数来实现标记的拖动,并且在 dragend 上我得到了新位置的 lat,lng.... ..
for (var key in data) {
if ((data[key]["latitude"] != null) & (data[key]["longitude"] != null)){
//populating the markers
if (data.hasOwnProperty(key) ) {
m = L.marker([data[key]["latitude"], data[key]["longitude"]], {
icon: compIcon,title:"Click and Hold Marker to drag",draggble:true
}).bindPopup(data[key]["name"]).addTo(comp_markers);
m.on('dragend', function(e) {
console.log("name of the marker :"+data[key]["name"]);
console.log("please show me changed lat & lon:"+this.getLatLng());
});
}
}
}
我的问题是:如何获取我拖动的标记的名称,但下面的行给出了数组中最后一个标记的名称........
console.log("name of the marker :"+data[key]["name"]);
我尝试了 this 关键字,期望它会指向用户拖动的确切标记......
console.log("name of the marker :"+this.data[key]["name"]);
我刚开始学习编程....请告诉我如何处理这种情况........谢谢
【问题讨论】:
标签: javascript