我无法找到明确的答案,异步Web sql真的让我感到沮丧。如何使用基于父SELECT查询的数据执行SELECT查询?这是我认为有效的片段,但实际上并非如此:
db.transaction(function(tx){
tx.executeSql('SELECT a, b FROM mytable WHERE c=5', [], function(tx,results) {
var i = results.rows.length;
while(i--){
var votes = results.rows.item(i).a;
var marker = results.rows.item(i).b;
tx.executeSql('SELECT a FROM mytable WHERE c=?', [marker], function(tx,aresults) {
if(!aresults){
//do something
} else {
myScore += (votes*100)/aresults.rows.item(0).a;
}
}(marker));
}
nextFunction();
});
}, function(){onError});
答案 0 :(得分:0)
试试这个:
function firstQuery(){
db.transaction(function(tx){
tx.executeSql('SELECT a, b FROM mytable WHERE c=5', [],
function(tx,results) {
var i = results.rows.length;
while(i--){
secondQuery(results.rows[i]);
}
});
}, function(){onError});
}
function secondQuery(responseQuery){
var votes = responseQuery.a;
var marker = responseQuery.b;
db.transaction(function(tx){
tx.executeSql('SELECT a FROM mytable WHERE c=?', [marker], function(tx,aresults) {
if(!aresults){
//do something
} else {
myScore += (votes*100)/aresults.rows.item(0).a;
}
}(marker));
}, function(){onError});
}