我正在构建一个Titanium iOS应用程序。我从服务器接收JSON数据并填充表。我在选择图像时换出的每一行都有一个图像,然后我会显示一个警告以确认他们的选择。我的问题是在警报中显示SELECTED行数据。这是我的代码:
//Create the row
var xhr = Ti.Network.createHTTPClient({
onload : function() {
Ti.API.debug(this.responseText);
var json = JSON.parse(this.responseText);
for ( i = 0; i < json.matches.length; i++) {
match = json.matches[i];
row = Ti.UI.createTableViewRow({
backgroundImage : 'images/matchesrowbackground.png',
selectionStyle : Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE,
width : '90%',
height : '180px'
});
var acceptmatchView = Ti.UI.createView({
left : '0px',
top : '0px',
width : '60px',
height : '60px'
});
var acceptmatch = Ti.UI.createImageView({
image : 'images/nomatch.png',
left : '0px',
top : '0px',
width : '60px',
height : '60px'
});
//Add some more stuff to the row and add the rows to the table then do my tableview.EventListener
tableview.addEventListener('click', function(e) {
var imageView = e.row.children[0].children[0];
if (imageView.image == 'images/nomatch.png') {
imageView.image = 'images/match.png';
var alertWindow = Titanium.UI.createAlertDialog({
title : 'Accept This Match?',
message : 'Are you sure you want to accept this match? ' + '\n' + match.matchtype + '\n' + 'Time: ' + match.datetime + '\n' + 'At: ' + match.cname,
cancel : 1,
buttonNames : ['Yes', 'Cancel']
});
如何让所选行数据显示在警报中?
答案 0 :(得分:1)
为此,您需要更改代码,如下所示
//Create the row
var xhr = Ti.Network.createHTTPClient({
onload : function() {
Ti.API.debug(this.responseText);
var json = JSON.parse(this.responseText);
for ( i = 0; i < json.matches.length; i++) {
match = json.matches[i];
row = Ti.UI.createTableViewRow({
backgroundImage : 'images/matchesrowbackground.png',
selectionStyle : Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE,
width : '90%',
height : '180px',
rowId : i //custom property
});
//Add some more stuff to the row and add the rows to the table
tableview.addEventListener('click', function(e) {
var imageView = e.row.children[0].children[0];
if (imageView.image == 'images/nomatch.png')
{
imageView.image = 'images/match.png';
var matchSelected = json.matches[e.rowData.rowId];
var alertWindow = Titanium.UI.createAlertDialog({
title : 'Accept This Match?',
message : 'Are you sure you want to accept this match? ' + '\n' + matchSelected.matchtype + '\n' + 'Time: ' + matchSelected.datetime + '\n' + 'At: ' + matchSelected.cname,
cancel : 1,
buttonNames : ['Yes', 'Cancel']
});
}
});
我正在使用自定义属性rowId
来识别所选行。