我正在使用 Titanium 构建 iOS 应用程序。我正在尝试在 tableView 中显示按字母顺序排列的列表。选择特定行时,我想将行信息传递到新窗口。The code I have displays the list alphabetically in groups with headers and I have an alphabetical scrollbar that when a letter is selected the list moves to that letter. However, when ANY row is selected, they all send the information for the last row in the database. 我认为我需要在行中有一个带有文本属性的标题元素,然后我可以有一个 tableview.addEventListener 抓住该标题并将其传递,但它不起作用。这是我正在使用的代码,如果有人可以看看我哪里出错了,将不胜感激。
var db = (function() {
var api = {};
api.all_item_names = function() {
var conn = Ti.Database.install('mydb.sqlite','clients');
var results = [];
var resultSet = conn.execute('select * from clients order by clientname asc');
while ( resultSet.isValidRow()) {
results.push({
clientname: resultSet.fieldByName('clientname'),
});
resultSet.next();
}
resultSet.close();
return results;
};
return api;
}());
var tvrow;
var curheader = 'A';
var list = [];
var index = [];
var data = [];
var isAndroid = (Titanium.Platform.name == 'android');
list = ( db.all_item_names() );
for ( var ipos=0; ipos<list.length;ipos++){
if( list[ipos].clientname[0] != curheader){
curheader = list[ipos].clientname[0];
tvrow = Titanium.UI.createTableViewRow({
height: 40,
path:'clientdetail.js' ,
client: list[ipos],
header: curheader
});
index.push({title:curheader, index:ipos});
} else {
tvrow = Titanium.UI.createTableViewRow({
height:40,
path:'clientdetail.js' ,
client: list[ipos]});
}
var title= Titanium.UI.createLabel({
left: 5,
top: 2,
height: 40,
color: '#000',
font: {fontSize: 16, fontWeight: 'bold', fontFamily: (isAndroid?'sans-serif':'Helvetica Neue')},
text: list[ipos].clientname });
tvrow.add(title);
data.push(tvrow);
}
var tableView = Titanium.UI.createTableView({
data: data,
index: index,
backgroundColor:'transparent',
separatorStyle: Titanium.UI.iPhone.TableViewStyle.GROUPED,
top: 1,
width: '99%'
});
tableView.addEventListener('click', function(e)
{
if (e.rowData.path)
{
var win = Ti.UI.createWindow({
url:e.row.path,
title:title.text
});
var clientlist = title.text;
win.clientlist = clientlist;
Ti.UI.currentTab.open(win);
}
});
win.add(tableView);