我已經創建了一個數組,它將存儲來自數據庫的動態值。當我在交易功能內打印數組時,它正在打印。當我試圖打印出一面時,我沒有得到價值。我已經在全局聲明瞭這個數組。有什麼問題,我的代碼如下;問題獲取數組值外的函數在JavaScript中?
function sendCategoryDetails() {
var selected_category = $('#select-choice :selected').val();
alert("control : " + selected_category);
var mycoodinatesDetails;
var myLocation = new Array();
var db = window.sqlitePlugin.openDatabase({name: "MYDB"});
db.transaction(function (tx) {
tx.executeSql("select Location from Locationlog WHERE Category = '"+selected_category+"';", [],
function (tx, res) {
for (var i = 0; i < res.rows.length; i++) {
myLocation[i] = res.rows.item(i).Location;
}
alert (myLocation +" length : "+ myLocation.length); // Values are printing
});
});
alert (myLocation +" length : "+ myLocation.length); // values are not getting, It showing the length is 0
}
有什麼建議嗎?
歡迎來到異步調用的世界。 – Satpal