0
我試圖從本地數據庫中提取數據,並將其顯示在使用自定義行的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);
}
}
問題解決!上面的代碼已被編輯以反映可用的代碼! – dnevels