hi guys,
I'm troubling at the moment with a typical closure problem. Following situation:
- I have table with rows
- the table has an eventlistener
- clicking on this table fires this eventlistener, which creates a view (which also should be clickable)
- the view should be clickable, so it also needs an eventlistener
- selectedViews is another view, which contains all the selectedView views (as you can see in the add()
method
my code is this:
$.myTable.addEventListener('click', function(e) { // some stuff var selectedView = Ti.UI.createView({ // some stuff }); selectedView.addEventListener('click', function(e) { console.log('got clicked'); // in fact I'll do here the removing of the view, if it gets clicked... }); $.selectedViews.add(selectedView); }but of course, it will not work, because of the scope of the variables.
I have already googled for it, but It doesn't helped...: - http://stackoverflow.com/questions/8133819/create-elements-and-addeventlistener-with-loop-in-titanium-appcelerator
I have already tried out with: - add all selectedView which have been created to an array - call a separate function, which iterates and does exactly this, which is described in the stackoverflow thread...
any suggestions?