0
我目前正在运行带有3个ObjectStores的IndexedDB函数和以下onupgradeneeded
函数。保持索引数据库升级时存在ObjectStore数据
var openRequest = indexedDB.open("DB_v3", 1);
openRequest.onupgradeneeded = function(e) {
var thisDB = e.target.result;
if(!thisDB.objectStoreNames.contains("ObjectStore1")) {
var objectStore = thisDB.createObjectStore("ObjectStore1", {autoIncrement:true});
objectStore.createIndex("name", "name", {unique:true});
}
if(!thisDB.objectStoreNames.contains("ObjectStore2")) {
//create objectstore & index as above
}
if(!thisDB.objectStoreNames.contains("ObjectStore3")) {
//create objectstore & index as above
}
}
我现在想要做的是添加第4个ObjectStore。 这对于我更改版本并在onupgradeneeded
中添加第4个条目。
var openRequest = indexedDB.open("DB_v4", 1);
openRequest.onupgradeneeded = function(e) {
//same as above
if(!thisDB.objectStoreNames.contains("ObjectStore4")) {
//create objectstore & index as above
}
}
所有这一切工作正常,但问题是,一旦onupgradeneeded
被调用已有的ObjectStores失去他们的所有数据。 onupgradeneeded
如何查看以保留已经存在的ObjectStore的数据?