javascript - Accessing custom rows of a TableView -


i pushing items data array , adding these rowdata array in order create custom rows table. need know how access these when user clicks specific row. using e.rowdata, title etc. accessing these elements when had basic table custom table, isn't working. don't worry parsing bit, works fine. appreciated!

data.push({              title: items.item(i).getelementsbytagname("title").item(0).text,                     leftimage: str.match(patt1) !== null ? str.match(patt1)[0] : 'image_news.png',             datatopass: items.item(i).getelementsbytagname("description").item(0).text,             haschild: true,              js:"external.js"         });        }      var rowdata=[];      for(i=0;i<data.length;i++){         var img= titanium.ui.createimageview({             image:data[i].leftimage,             left:0,             bottom:5,             height: 100,             width: 100         });          var bgbar=titanium.ui.createview({             height:110,             width: "100%",             bottom:0,             left:0,             backgroundcolour: "#000",             opacity: 0.6         });          var title=titanium.ui.createlabel({             text:data[i].title,             color: 'black',             left: 105         });          var row=titanium.ui.createtableviewrow({             height: "auto",             haschild: "true",         js:"external.js",         datatopass: data[i].datatopass         });          row.add(img);         row.add(bgbar);         row.add(title);            rowdata.push(row);         console.log("row shiznick" + rowdata);     }       tableview.setdata(rowdata);   tableview.addeventlistener("click", function (e){         console.log("here source.title ------------------"+e.row.title);         console.log("yoyooyoyo------------"+e.source.title);         console.log("is it---------------"+e.children[0]);         console.log("here source -----------------------------"+ e.source);         console.log("here source.leftimage reg exp3 ------------------"+e.row.leftimage);         console.log("here source.classname ------------------"+e.source.classname);         console.log("here haschild ------------------"+e.rowdata.haschild);         console.log("here datatopass ------------------"+e.row.datatopass); }); 

there 2 ways set rows of table, can create custom rows, or create json objects have attributes of row object. both cases have different ways of accessing row, either row object or rowdata object, from docs:

when row created implicitly using javascript dictionary object, use [the rowdata property] rather row access custom row properties. here's example of creating row implicitly, not recommended way.

in example, since did not create row objects implicitly, explicitly, can access clicked row row attribute of event this:

tableview.addeventlistener("click", function(e){     // [tableviewrow](http://docs.appcelerator.com/titanium/latest/#!/api/titanium.ui.tableviewrow) object     var therow = e.row;     // children     var rowchildren = therow.children;     // here objects in row     var imginrow = rowchildren[0];     var bgbarinrow = rowchildren[1];     var titleinrow = rowchildren[2];     // here title     var rowtitle = titleinrow.text; }); 

alternatively, in both cases, use index row object this:

tableview.addeventlistener("click", function(e){     // index of row     var ndx = e.index;     // row, works if have not added sections     var row = tableview.data[ndx]; }); 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -