在一個ionic1項目中,需求要做到離線數據庫功能,故使用了cordova中的sqlite插件,數據庫中的數據會由首次加載app時請求后臺數據獲??;但這時發現貌似無法在異步操作中調用sqlite操作,比如最簡單的定時器:$timeout(function(){ //執行sqlite操作},1000);此時定時器內部的函數并不會執行,并且報錯:"InvalidStateError: DOM Exception 11: This transaction is already finalized. Transactions are committed after its success or failure handlers are called. If you are using a Promise to handle callbacks, be aware that implementations following the A+ standard adhere to run-to-completion semantics and so Promise resolution occurs on a subsequent tick and therefore after the transaction commits."而之后嘗試使用了jq的ajax并將其修改為了同步執行:$.ajax({ data: data, url: url, type: 'post', timeout: 3000, async: false, success: function(data){ //執行sqllite操作 }, error: function() { //error }})此時就不再會報之前的一長串錯誤并且成功回調能夠正常執行;但是實際項目中不可能使用這種極有可能阻塞整個app的方法(比如用戶信號不佳),請問是否有解決方法能夠讓sqlite在異步操作中執行?
是否無法在異步操作中中使用cordova中調用sqlite
牧羊人nacy
2018-12-13 14:10:05