我使用下面的代碼來讀取索引數據庫的數據並將其保存在變量allDownloadContent存儲檢索從索引數據庫的數據給一個變量
ereaderdownload.indexedDB.getAllTodoItems = function() {
/*var todos = document.getElementById("todoItems");
todos.innerHTML = "";
*/
var db = ereaderdownload.indexedDB.db;
var trans = db.transaction(["downloadcontent"], "readwrite");
var store = trans.objectStore("downloadcontent");
var request = store.get(0);
request.onsuccess = function(e) {
console.log(e.target.result);
};
// Get everything in the store;
var cursorRequest = store.openCursor();
cursorRequest.onsuccess = function(e) {
var result = e.target.result;
if(!!result == false)
return;
allDownloadContent.push(result);
result.continue();
};
alert("content "+allDownloadContent[0]);
cursorRequest.onerror = ereaderdownload.indexedDB.onerror;
};
當我打電話getAllTodoItems方法從我得到另一個JavaScript文件一個警告消息內容不確定
因爲cursorRequest.onsuccess方法執行異步我越來越不確定。
我不能使用網絡工作者,因爲它在chrome中不受支持。
我在JQuery中試過諾言。我仍然收到相同的警報消息。
請幫我解決這個問題。
你是什麼意思的網絡工作者不支持在Chrome? http://caniuse.com/webworkers – KKetch
我的意思是同步indexeddb api – aaviss
我想你想在你編寫'return'的回調中提醒。那時數據可用。 – pimvdb