我的代码如下所示:
if (ACTIVETICKETS.length > 0)
{
for (var m in ACTIVETICKETS)
{
if (ACTIVETICKETS.hasOwnProperty(m))
{
var marker = new L.Marker(new L.LatLng(ACTIVETICKETS[m].location.x, ACTIVETICKETS[m].location.y));
createHtmlForPopUp(m, function(data)
{
console.log(m);
marker.bindPopup( data ); // calling a function with callback
tile_layer.addLayer(marker);
});
}
} // for loop ends here
}
在执行此操作时,我只得到 m 的最后一次迭代。ACTIVETICKETS 数组的总长度是 16。所以我只输入了 15 个 16 次