我对 IndexedDB 概念很陌生。我正在尝试在 IndexedDB 中存储电影列表并检索它。但是由于某种原因,当我尝试检索它时,chrome 浏览器中有一个 DOM IDBDatabase Exception 11。我尝试使用一个简单的警报来检索它。我还尝试通过将警报放在 onComplete 事件中来检索数据,但这似乎也失败了。有人可以让我知道我做错了什么。下面是我的代码。
const dbName = "movies";
var request = indexedDB.open(dbName, 1);
request.onerror = function(event) {
alert("Seems like there is a kryptonite nearby.... Please Check back later");
};
request.onsuccess = function(event) {
var db = event.target.result;
var transaction = db.transaction(["movies"],"readwrite");
var objectStore = transaction.objectStore("movies");
var request1 = objectStore.get("1");
request1.result.oncomplete=function(){
alert("The movie is"+request1.result.name);//This is the place where i get the error
}
};
request.onupgradeneeded = function(event) {
db = event.target.result;
var objectStore = db.createObjectStore("movies", { keyPath: "movieid" });
objectStore.createIndex("name", "name", { unique: false });
objectStore.createIndex("runtime", "runtime", { unique: false });
for (var i in movieDataToStore) {
objectStore.add(movieDataToStore[i]);
}};