Javascript 在processmethod之前调用回调

Javascript 在processmethod之前调用回调,javascript,cordova,Javascript,Cordova,嘿,我正在使用phonegap数据库,试图理解为什么在process方法完成之前调用我的回调,下面是js代码和表明我声明的日志 下面是代码:(首先调用的方法是insertIntoDB(x,y);) 以下是cordova/my app的日志: 08-01 12:09:02.857: D/DroidGap(24433): onMessage(spinner,stop) 08-01 12:09:03.467: D/CordovaLog(24433): starting doInsertion 08-0

嘿,我正在使用phonegap数据库,试图理解为什么在process方法完成之前调用我的回调,下面是js代码和表明我声明的日志

下面是代码:(首先调用的方法是insertIntoDB(x,y);)

以下是cordova/my app的日志:

08-01 12:09:02.857: D/DroidGap(24433): onMessage(spinner,stop)
08-01 12:09:03.467: D/CordovaLog(24433): starting doInsertion
08-01 12:09:03.467: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 24 : starting doInsertion
08-01 12:09:03.472: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9747386311565038, null, 9765, img, 1, 0, null, /content/picture/menu/product, null, null, mainMenu.menu, showProductCatalog(product), null, Y, 0);
08-01 12:09:03.477: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9747386311565038, null, 9765, img, 1, 0, null, /content/picture/menu/product, null, null, mainMenu.menu, showProductCatalog(product), null, Y, 0);
08-01 12:09:03.477: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9847155498013517, null, 9753, img, 1, 1, null, /content/picture/menu/social, null, null, mainMenu.menu, showSocialMedia(socialmedia), null, Y, 0);
08-01 12:09:03.477: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9847155498013517, null, 9753, img, 1, 1, null, /content/picture/menu/social, null, null, mainMenu.menu, showSocialMedia(socialmedia), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.5451258043474583, null, 9759, img, 1, 2, null, /content/picture/menu/store, null, null, mainMenu.menu, menu(store), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.5451258043474583, null, 9759, img, 1, 2, null, /content/picture/menu/store, null, null, mainMenu.menu, menu(store), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.6883956226802171, null, 9762, img, 1, 3, null, /content/picture/menu/showroom, null, null, mainMenu.menu, showCollection(collection), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.6883956226802171, null, 9762, img, 1, 3, null, /content/picture/menu/showroom, null, null, mainMenu.menu, showCollection(collection), null, Y, 0);
08-01 12:09:03.487: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.21612715546682493, null, 9768, img, 1, 4, null, /content/picture/menu/beskeder, null, null, mainMenu.menu, showNotificationList(notificationList), null, Y, 0);
08-01 12:09:03.487: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.21612715546682493, null, 9768, img, 1, 4, null, /content/picture/menu/beskeder, null, null, mainMenu.menu, showNotificationList(notificationList), null, Y, 0);
08-01 12:09:03.497: D/CordovaLog(24433): now doInsertion (if successful should be called
08-01 12:09:03.497: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 7 : now doInsertion (if successful should be called

您正在调用回调,而不是传递回调:

db.transaction(createMenuDataBase, errorCB, callback(dbName,json));

callback(dbName,json) //Calls the function and passes the result to `db.transaction` as callback but it's not a function since the result is not a function.
试试这个:

db.transaction(createMenuDataBase, errorCB, callback);
如果
回调
需要这些参数,则:

db.transaction(createMenuDataBase, errorCB, callback.bind( null, dbName, json ));
db.transaction(createMenuDataBase, errorCB, callback.bind( null, dbName, json ));