Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Problem for create element and eventListeners in loop

$
0
0

Hi !

I try to create elements and eventListeners in loop "for". But the system keeps the last event of the loop and has applied all items.

function parseData(jsonData){
            var tableData = [];
            var section = [];
            for(i=0; i<3;i++){
 
                section[i] = Ti.UI.createTableViewSection({ headerTitle: "nameLink"});
                section[i].add(Ti.UI.createTableViewRow({ title: "enabledLink", backgroundColor: "green", hasChild:true}));     
                //click : open new windows
                section[i].addEventListener('click', function(e) {
                    window.containingTab.open(Ti.UI.createWindow({
                        title: L('test: '+i),
                        backgroundColor: 'white',           
                    }););
                });
 
                tableData.push(section[i]);
 
                }           
 
            table.data= tableData;
        }
How do I obtain a different window for each element/event ?

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>