我有一个有效的 PhoneGap 数据库事务,我可以在其中运行 sql 查询并处理结果。但是,为了使其可重用,我需要将参数传递给查询函数。应该有比在查询函数中声明全局变量并访问它们/重置更好的方法。感谢任何帮助转换它:
//update images function
function updateGalleryCovers() {
var db = window.openDatabase("test db", "1.0", "Cordova DB", 200000);
db.transaction(queryDB_u_g, errorCB);
}
//Query the database
function queryDB_u_g(tx) {
var query = 'SELECT cover_img, objectId FROM USER_GALLERY WHERE userId="'+getUserId()+'"';
tx.executeSql(query, [], querySuccess_u_g, errorCB);
}
//Query success callback
function querySuccess_u_g(tx, results) {
var len = results.rows.length;
for (var i=0; i<len; i++){
// process results
}
}
像这样:
//update images function
function updateGalleryCovers(userid) {
var db = window.openDatabase("test db", "1.0", "Cordova DB", 200000);
db.transaction(queryDB_u_g, userid, errorCB);
}
//Query the database
function queryDB_u_g(tx, userid) {
var query = 'SELECT cover_img, objectId FROM USER_GALLERY WHERE userId="'+userid+'"';
tx.executeSql(query, [], querySuccess_u_g, errorCB);
}
//Query success callback
function querySuccess_u_g(tx, results) {
var len = results.rows.length;
for (var i=0; i<len; i++){
// process results
}
}
谢谢!