2013-08-24 29 views
1

我是TideSDK的新手,所以我正在做一些測試。我發現API有一些方法來管理和檢索存儲在本地數據庫中的數據。我創建了一個名爲Users的表,只有兩個字段,即id和name(這是http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Database.DB的示例),我填充了一些隨機數字和名稱。這是我正在使用的功能:使用TideSDK API無法獲取查詢結果中的所有行

function consulta(){ 
//Open the database first 
var db = Ti.Database.openFile(Ti.Filesystem.getFile(
          Ti.Filesystem.getApplicationDataDirectory(), 'customdatabase.db')); 

var rows = db.execute(「SELECT * FROM Users ORDER BY firstName」);

while (rows.isValidRow()) { 

    document.getElementById('resultado').innerHTML = 'The user id is '+rows.fieldByName('id')+', and user name is '+rows.fieldByName('firstName')+'<br>'; 
rows.next();  
} 
document.getElementById('filas').innerHTML = rows.rowCount(); 
//Release memory once you are done with the resultset and the database 
rows.close(); 
db.close(); 
}** 

我的問題是這樣的:雖然方法rowCounts的()的結果是29(意思是,當然,也有在結果29行),該WHILE塊剛剛走出puting一個單列代替。有人可以幫我做這個工作嗎?我不應該使用這個API嗎?

回答

1

簽出數據庫模塊的示例API用法here

1

試試這個:

while (rows.isValidRow()) { 

document.write('The user id is '+rows.fieldByName('id')+', and user name is '+rows.fieldByName('firstName')+'<br >'); rows.next(); } document.getElementById('filas').in nerHTML = rows.rowCount(); //Release memory once you are done with the resultset and the database rows.close(); db.close(); } 

將身體內的腳本