簡體   English   中英

從回調函數調用其他函數

[英]calling other function from callback function

我希望獲得一些幫助...會被卡住一段時間。

var inventoryID = '123456';

function pickupFail(){
    db = window.openDatabase("myInvetory", "1.0", "myInvetory", 200000);
    db.transaction(queryUpdateInventory, dbError);
}

function queryUpdateInventory(tx){
    var sql = "SELECT inventoryCount FROM Inventory WHERE inventoryID = ?";
    tx.executeSql(sql, [inventoryID], finalizeUpdateInventory, dbError);
}

function finalizeUpdateInventory(tx, results){
   ....
   var inventoryCount = 0;
   var inventory = results.rows.item(0);
   ....
   inventoryCount = inventory.count;
   ....
   ....
   otherFunction(inventoryCount); // CALLING THIS PRODUCE CALLBACK ERROR
   ....
}

function otherFunction(count,...){
   ....
   //THIS IS LENGTHILY FUNCTION AND BEING USED BY OTHER FUNCTION AS WELL

}

坦率地說,我對Cordova和javascript回調概念非常陌生。 我真的很感謝你們的幫助。

您正在調用一個函數並在以后定義它。 finalizeUpdateInventory() otherFunction(count)之前定義otherFunction(count)應該可以消除該錯誤。 因此,修改后的代碼變為:

var inventoryID = '123456';

function pickupFail(){
    db = window.openDatabase("myInvetory", "1.0", "myInvetory", 200000);
    db.transaction(queryUpdateInventory, dbError);
}

function queryUpdateInventory(tx){
    var sql = "SELECT inventoryCount FROM Inventory WHERE inventoryID = ?";
    tx.executeSql(sql, [inventoryID], finalizeUpdateInventory, dbError);
}

function otherFunction(count,...){
   ....
   //THIS IS LENGTHILY FUNCTION AND BEING USED BY OTHER FUNCTION AS WELL

}

function finalizeUpdateInventory(tx, results){
   ....
   var inventoryCount = 0;
   var inventory = results.rows.item(0);
   ....
   inventoryCount = inventory.count;
   ....
   ....
   otherFunction(inventoryCount); // CALLING THIS PRODUCE CALLBACK ERROR
   ....
}

我終於在otherFunction中發現了錯誤。 似乎otherFunction正在調用同一頁面中不存在的html元素。 此html元素存在於其他使用otherFunction的頁面中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM