Question

what i need to do is simple yet i cant get my head around it . i want to get the id of the Row thats been clicked so i can navigate to the next window based on that ID , the Id's and the listitems are fetched from external source via JSON and stored in NumberOfLists array

 Titanium.UI.setBackgroundColor('#000');

// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
    title : 'Main Window',
    backgroundColor : '#fff'
 });

var listUrl = "http://magadhena.com/test/list.php?FCODE=5&USERID=1";
var NumberOfLists = [];
var listsJson;
var tableData = [];
var table = Ti.UI.createTableView({
    top : 40,
    left : 10,
    width : 300
 });


 var xhr = Ti.Network.createHTTPClient();
 xhr.setTimeout(3000);
 xhr.onload = function() {
    listsJson = eval('(' + this.responseText + ')');
    for(var i = 0; i < listsJson.length; i++) {
            var userId = listsJson[i].userid;
            var listId = listsJson[i].listid;
            var listName = listsJson[i].listname;

            var Object1 = new list(userId, listId, listName);

            NumberOfLists.push(Object1);


            var row = Ti.UI.createTableViewRow({
            title : Object1.listName,
            hasDetail:true
    });

    tableData.push(row)

    }
    table.setData(tableData);


};
 xhr.open("GET", listUrl);
 xhr.send();

 win1.add(table);



 // Opening Window1

win1.open();

///// List Objects

   function list(userid, listid, listname) {
    this.userId = userid;
    this.listId = listid;
    this.listName = listname;

}
Was it helpful?

Solution

modifie your onload. usually you can declare custom properties to your row object like this

var Object1 = new list(userId, listId, listName);

NumberOfLists.push(Object1);


var row = Ti.UI.createTableViewRow({
   title : Object1.listName,
   hasDetail:true,
   remoteObject: Object1 /* your custom property */
});

this propery should be easy to read in the tableview click event:

table.addEventListener('click',function(e){
   var _clickedRow = e.row;
   Ti.API.debug("userID:" +_clickedRow.remoteObject.userId);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top