我正在使用以下代码从 Web SQL 数据库中获取分层数据:
...
function getResult(query, data, callback){
db.transaction(function(tx) {
tx.executeSql(query, data, function(tx, result) {
callback(result);
});
});
}
function findChildren(id){
getResult("SELECT * FROM my_table WHERE parent_id=?", [id], function(result){
for (var i = 0, item = null; i < result.rows.length; i++) {
item = result.rows.item(i);
data.push(item);
findChildren(item.id);
}
});
}
var data = Array();
getResult("SELECT * FROM my_table WHERE name like ?", ["A"], function(result){
for (var i = 0, item = null; i < result.rows.length; i++) {
item = result.rows.item(i);
data.push(item);
findChildren(item.id);
}
});
...
如何检测执行是否已完成?