1
我基本上有這樣的代碼來生成一個對象存儲一個新的數據庫:無法創建第二個對象存儲IndexedDB的
DB.open_or_create({table: 'photos', key: 'url'});
和主代碼:
var DB = {
open_or_create : function(p){
var openRequest = indexedDB.open("new_app",1);
openRequest.onupgradeneeded = function(e) {
var thisDB = e.target.result;
if(!thisDB.objectStoreNames.contains(p.table)) {
thisDB.createObjectStore(p.table,{ keyPath: p.key });
}
}
openRequest.onsuccess = function(e) {DBTABLES = e.target.result}
openRequest.onerror = function(e) {console.log(e)}
}
然後我試圖添加第二個對象存儲與命令:
DB.open_or_create2({table: 'users',key: 'id'});
而且基本上只有與另一個數據庫版本號相同的代碼:
open_or_create2 : function(p){
var openRequest = indexedDB.open("new_app",2);
openRequest.onupgradeneeded = function(e) {
var thisDB = e.target.result;
if(!thisDB.objectStoreNames.contains(p.table)) {
if(p.key){
thisDB.createObjectStore(p.table,{ keyPath: p.key });
}else{
thisDB.createObjectStore(p.table)
}
}
}
openRequest.onsuccess = function(e) {DBTABLES = e.target.result}
openRequest.onerror = function(e) {console.log(e)}
}
但是正如我在控制檯中所看到的,只有第一個表被創建!此外,當我嘗試將數據添加到患者表我得到這個錯誤:
Uncaught NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
我該怎麼做?謝謝!