1 function TestDB() { 2 var request = window.indexedDB.open("/idbfs"); 3 request.onsuccess = function (event) { 4 var db = request.result; 5 console.log(‘数据库打开成功‘); 6 7 var objectStore = db.transaction(‘FILE_DATA‘).objectStore(‘FILE_DATA‘); 8 objectStore.openCursor().onsuccess = function (event) { 9 var cursor = event.target.result; 10 if (cursor) { 11 console.log(‘key: ‘ + cursor.key); 12 console.log(‘mode: ‘ + cursor.value.mode); 13 if(cursor.value.contents){ 14 console.log(‘contents: ‘ + Uint8ArrayToString(cursor.value.contents)); 15 } 16 cursor.continue(); 17 } else { 18 console.log(‘没有更多数据了!‘); 19 } 20 }; 21 }; 22 } 23 24 function Uint8ArrayToString(fileData){ 25 var dataString = ""; 26 for (var i = 0; i < fileData.length; i++) { 27 dataString += String.fromCharCode(fileData[i]); 28 } 29 return dataString 30 }