Finally i got solution of my problem by exploring Javascript a bit in detail.
Its about Javascript Closures in which In-line function fail to transfer outer-world variable. So We've to store that outer-world variable into a local variable inside the In-line function and start using local variable now. But we also have to use (); at the end of the function which is like a magic statement.
Here is code that exactly looks like
for(var i=0; i<jsonObject.length; i++){
closePOIImgDrw.onClick = (function(){
var currentIndex = i;
return function(){
alert('My ID:'+currentIndex);//Here i'm using currentIndex local variable name not outer-function.
removeSinglePOI(currentIndex);
}
})();
}//for end
It is working fine in my case and I'm glade to share this solution with others whoever get stuck in same kinda problem.
Can you please guide here what went wrong? Or Param variable doesn't accesible inside the anonymous function?
Regards!
Aamir Ali
C
Christian Ebner
said
almost 11 years ago
Hello,
you don't return a boolean in your click-functions createClickTrigger and testBtnClick. If you don't return anything the next click-trigger will be fired. It should be enough to "return true;" at the end of both functions.
You find more details about the onClick-trigger in the reference.
Hope that helps, Chris
A
Aamir Ali
said
almost 11 years ago
Hi All,
I'm displaying 1 Background Image and 1 small X button to close the box.
Calling a function on a close button which is on top of a background. Btw Background also has a click listener.
Now when i click on POI/Background it works but when i click on close-button, it doesn't respond. Why?
Is it because of the priority..? Like IF the container (Background) also has click-listener then all the sub component on it will get fail to respond to their listener?
Is there anyone who faced same issue and now resolved it?
If anyone knows the root cause of it or it's solution, please do share it with me. Thanks in advance.
Aamir Ali