난 그냥 jQuery
를 사용하여 링크에 따르면 Return a COUNT from a WebSQL query in a javaScript function
를 사용하는 것이 이렇게되면 그렇게 관리하고 그것을 작동합니다! 그러나 javaScript
답을 갖고 싶습니다.
function getCustomerAccountDetails(){
var defer = $.Deferred();
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM contacts', [], function(tx, results) {
defer.resolve(results.rows);
});
});
return defer.promise();
}
function exampleThatUsesUserArray(data) {
//do something that uses count here
return data;
}
var dataArray = getCustomerAccountDetails();
$.when(dataArray).done(function(data) {
//now use count, could be you call another function that needs to use count,
//getCustomerAccountDetails();
alert(exampleThatUsesUserArray(data.length) + " Row Count");
for(var i = 0; i < data.length; i++){
alert((i+1) + "-" + data.item(i)['id'] + "-" + data.item(i)['firstname'] + "-"
+ data.item(i)['lastname'] + "-" + data.item(i)['phonenumber']);
}
//or assign it to another variable, or trigger an event that someone else in you app is listening for
});