我正在尝试从本地数据库中提取数据并将其显示在使用自定义行的 tableview 中。我不知道如何让它正确显示。它当前的写入方式将显示一行,其中正确显示了数据,但它似乎显示了数千个空行。我认为我的问题是因为我有两个while (rows.isValidRow())
陈述。有人可以告诉我正确显示的代码吗?这是我当前的代码:
//Setup the window
var win = Titanium.UI.currentWindow;
win.barColor='#000000';
//install database
var db = Ti.Database.install('bcapool3.sqlite','distributor');
//Get data
var rows = db.execute('SELECT * FROM distributor');
// create table view
var tableview = Ti.UI.createTableView({
backgroundColor:'transparent',
color: '#000000',
top:80,
height:'auto',
left:80,
right:80,
bottom:120
});
function setData() {
while (rows.isValidRow())
{
var dataArray = [];
var row = Ti.UI.createTableViewRow({
haschild: true,
path: 'distributordetail.js'
});
var title = Ti.UI.createLabel({
color:'#000000',
height:32,
left:5,
top:2,
font:{fontSize:'18dp',fontWeight:'bold' },
backgroundColor:'transparent',
text:'' + rows.fieldByName('distributor_name') + ''
});
var address = Ti.UI.createLabel({
color:'#000000',
height:32,
left:5,
top:34,
fontSize:'14dp',
backgroundColor:'transparent',
text:'' + rows.fieldByName('distributor_address') + ''
});
var distance = Ti.UI.createLabel({
color:'#000000',
height:32,
right: 10,
top:34,
fontSize:'12dp',
backgroundColor:'transparent',
text:'' + rows.fieldByName('distance') + ''
});
row.add(title);
row.add(address);
row.add(distance);
tableview.add(row);
row.className = 'distributorRow';
dataArray.push(row);
rows.next();
}
// set the array to the tableView
tableview.setData(dataArray);
}
}