I typically, call this to query back the result:
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM MyDB WHERE key = ?', [aKey], MyDB.renderResults);
});
and the renderResults function is like that:
renderResults: function(tx, rs){
// for(i = 0; i < rs.rows.length; i++){
// document.getElementById("textfield").value = "";
// document.getE开发者_C百科lementById("textarea").value += rs.rows.item(i).chiChar;
// }
}
But I would like to make it more flexible, I would like to assign a function as a param to renderResults, in order to make my renderResult can execute a call back function. In other words,I would like to put the commented code into a function, which the renderResults only execute the function I put .....How can I do so ?? Thank you.
renderResults: function(tx, rs, callback){
callback(tx, rs);
}
function foo(tx, rs) {
for(i = 0; i < rs.rows.length; i++){
document.getElementById("textfield").value = "";
document.getElementById("textarea").value += rs.rows.item(i).chiChar;
}
}
renderResults(tx, rs, foo);
精彩评论