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 - 参考示例:待办事项通知(查看实时示例)。