开发者

Have a custom tableview, how to give a given row a hidden id# variable?

I have a custom built tableview, where I am building the text i开发者_开发百科n the table row by row. I have a big loop that goes through a set of XML data and builds the row based on an RSS XML feed.

Then I added an event listener to see when somone clicks on one of the rows:

tableview.addEventListener('click',function(e)
{
    showrow(theid);
});

My question is, during the building of the row, how do i define theid as a variable associated with that row?

I tried a simple

    var theid = item.getElementsByTagName("id").item(0).text;

in my loop, but that does work as its always set to the last item in my loop of XML entries.

Thanks!


As you are creating the TableViewRows in your loop, just add the 'theid' property to it with dot notation

var row = Ti.UI.createTableViewRow();
row.theid = item.getElementsByTagName("id").item(0).text;
row.addEventListener('click', function(e){
  alert( e.source.theid );
});

Note: If you are adding additional objects on your TableViewRow (like images, labels, etc) make sure you look at the event propagation in the KitchenSink to make sure that 'e.source' is the tableViewRow and not the UI objects added to the tableViewRow

If you want to add the eventListener to the table (not the row) just check the 'rowData' of the click:

table.addEventListener('click', function(e){
  alert( e.rowData.theid );
});


you should add custom variables to your row like

var newRow = Ti.UI.createTableViewRow({
  title: 'my new row',
  customID: item.getElementsByTagName('id').item(0).text
});

tableViewRow.add(newRow);

if that doesn't work, try this:

var newRow = Ti.UI.createTableViewRow({
  title: 'my new row',
  'customID': item.getElementsByTagName('id').item(0).text
});

tableViewRow.add(newRow);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜