my code look like this:
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
}
While executing this, I am getting only the last iteration of m. Total length of ACTIVETICKETS array is 16. So I am getting only 15 entered 16 time
The code below should work, but as I commented above, please read about closure so you know why.
if (ACTIVETICKETS.length > 0) {
for (var m in ACTIVETICKETS) {
(function(x) {
if (ACTIVETICKETS.hasOwnProperty(x)) {
var marker = new L.Marker(new L.LatLng(ACTIVETICKETS[x].location.x, ACTIVETICKETS[x].location.y));
createHtmlForPopUp(x, function(data){
console.log(x);
marker.bindPopup( data ); // calling a function with callback
tile_layer.addLayer(marker);
});
}
})(m);
} // for loop ends here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With