IndexedDB は、大量の構造化データを保存する API です。このデモでは、非同期 API が使用されています。この API に慣れている限り、問題は、indexedDB でのすべての操作が非同期の「リクエスト」になることです。操作はとても簡単です。
一般的なプロセスは次のとおりです
1. データベースを開きます
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB;
if ('webkitIndexedDB' in window) {
window.IDBTransaction = window.webkitIDBTransaction;
window.IDBKeyRange = window.webkitIDBKeyRange;
}
var request = indexedDB.open( "adsageIDB" );
request.onsuccess = function (e) {
var v = "1.00" ;
var db = e.target.result;
if (v!= db.version) {
var setVrequest = db.setVersion(v);
setVrequest.onsuccess = function (e) {
if (db.objectStoreNames.contains( "todo" )) {
db.deleteObjectStore( "todo" );
}
var store = db.createObjectStore( "todo" , {keyPath: "adsid" });
}
}
}
|
ログイン後にコピー
これにより、インタラクティブなオブジェクトを作成し、DOMイベントをリッスンし、データを処理します
それから、データベースを操作したいR
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | var trans = db.transaction([ "todo" ], IDBTransaction.READ_WRITE);
var store = trans.objectStore( "todo" );
var data = {
"text" : todoText,
"adsid" : new Date ().getTime()
};
var request = store.put(data);
request.onsuccess = function (e) {
};
request.onerror = function (e) {
console.log( "Error Adding: " , e);
};
|
ログイン後にコピー
e
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | var trans = db.transaction([ "todo" ], IDBTransaction.READ_WRITE);
var store = trans.objectStore( "todo" );
var keyRange = IDBKeyRange.lowerBound(0);
var cursorRequest = store.openCursor(keyRange);
cursorRequest.onsuccess = function (e) {
var result = e.target.result;
if (!!result == false)
return ;
console.log(result.value);
result. continue ();
};
|
ログイン後にコピー
ee
rreeeee
就就就就就就就就就就就in indexeddb(推奨)は、Xiaobianによってすべてのコンテンツに共有されています詳細については、PHP 中国語 Web サイト (www.php.cn) をご覧ください。
-->