IDBVersionChangeEvent:oldVersion 屬性
注意:此功能在 Web Workers 中可用。
oldVersion 是 IDBVersionChangeEvent 介面的一個只讀屬性,它返回資料庫的舊版本號。
當開啟的資料庫尚不存在時,oldVersion 的值為 0。
值
一個包含 64 位整數的數字。
示例
js
const dbName = "sampleDB";
const dbVersion = 2;
const request = indexedDB.open(dbName, dbVersion);
request.onupgradeneeded = (e) => {
const db = request.result;
if (e.oldVersion < 1) {
db.createObjectStore("store1");
}
if (e.oldVersion < 2) {
db.deleteObjectStore("store1");
db.createObjectStore("store2");
}
// etc. for version < 3, 4…
};
規範
| 規範 |
|---|
| Indexed Database API 3.0 # dom-idbversionchangeevent-oldversion |
瀏覽器相容性
載入中…
另見
- 使用 IndexedDB
- 開始事務:
IDBDatabase - 使用事務:
IDBTransaction - 設定鍵的範圍:
IDBKeyRange - 檢索和修改資料:
IDBObjectStore - 使用遊標:
IDBCursor - 參考示例:待辦事項通知(檢視即時示例)。