Stupid me. The code I wrote you actually executes the function (returning nothing, hence the undefined error you get):
(function(x) { ... })(x);
while instead should return one. So either you change it to do so:
for (x in charts) {
listener[x] = g.v.events.addListener(charts[x]['chart'], 'ready' , (function(x) {
return function() {
// do something with 'x'
};
})(x));
...
}
but that becomes really verbose. So you can lock the 'x' just inside the for loop and achieve the same result in a slightly more compact way:
for (x in charts) {
(function(x) { // 'x' is now locked by the closure
g.v.events.addListener(charts[x]['chart'], 'ready', function() { /* your listener code */ });
})(x);
}
Again, haven't tried the above in a live example, so let's hope I didn't write something wrong again :-).
Another reference reading, for better understanding:
( look at the 'saving state with closures' paragraph, that describes exactly the 2 techniques I mentioned above).
- R.
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.