0
データベースを作成し、通常は正常に機能する基本的な操作を実行できるようにする次のコードがあります。私は削除機能を使用し、ページをリフレッシュすると(すべてのブラウジングデータなどを消去した後も含めて)、データベースは再び開かれず、私は未定義のエラー、アイデアを得ますなぜこれが起こっているのか?インデックス付きDB - データベースが削除されて別の名前を付けた後に未定義
p.s.私は、このエリアには、などを追加/削除する機能が含まれていますが、私はこの質問の目的のために取り出されている//これは、私は新しいもの
// Browser support detection
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
// Transaction object for use with CRUD
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
(function() {
var db;
var memberInfo = [
{ memID: "001", forename: "John", surname: "Smith", dob: "23/01/1987", password: "password123", gID: "1" },
{ memID: "002", forename: "Bob", surname: "Smith", dob: "17/05/1934", password: "password123", gID: "2" },
{ memID: "003", forename: "Frank", surname: "Smith", dob: "17/05/1990", password: "password123", gID: "2" },
{ memID: "004", forename: "Alan", surname: "Smith", dob: "17/05/1985", password: "password123", gID: "1" },
{ memID: "005", forename: "Tony", surname: "Smith", dob: "17/05/1978", password: "password123", gID: "3" }
];
var gradeInfo = [
{ gID: "1", type: "GOLD", cost: "£200.00" },
{ gID: "2", type: "SILVER", cost: "£125.00" },
{ gID: "3", type: "BRONZE", cost: "£75.00" }
];
var facInfo = [
{ memID: "001", factype: "Squash"},
{ memID: "001", factype: "Martial Arts"},
{ memID: "002", factype: "Swimming"},
{ memID: "004", factype: "Squash"},
{ memID: "004", factype: "Tennis"},
{ memID: "004", factype: "Swimming"},
{ memID: "005", factype: "Football"},
{ memID: "005", factype: "Archery"}
];
function initDb() {
// Open call is used to open database with given name & set DB version
var request = indexedDB.open("HaleSportsClub", 1);
// Function used to get database object from request and store for user
request.onsuccess = function (evt) {
db = request.result;
};
request.onerror = function (evt) {
alert("Database did not open: " + evt.target.message); // !!!!!
};
// Fire when version is smaller than one provided (by open call)
request.onupgradeneeded = function (evt) {
var db = evt.target.result;
// Each object store resembles a table in RDBMS
var memberObject = db.createObjectStore("members", { keyPath: "memID" });
var gradeObject = db.createObjectStore("grades", { keyPath: "gID" });
var facObject = db.createObjectStore("facilities", { keyPath: "memID" });
// Creates searchable indexes (??)
memberObject.createIndex("forename", "forename", { unique: false });
memberObject.createIndex("surname", "surname", { unique: false });
memberObject.createIndex("gID", "gID", { unique: false });
facObject.createIndex("memID", "memID", { unique: false });
for (i in memberInfo) {
memberObject.add(memberInfo[i]);
}
for (i in gradeInfo) {
gradeObject.add(gradeInfo[i]);
}
for (i in facInfo) {
facObject.add(facInfo[i]);
}
};
request.onblocked = function (evt){
alert("database currently being upgraded, try again soon");
}
}
function contentLoaded() {
initDb();
を作成しようとしていた、データベースは削除機能よりも、差分の名前を持って知っていますアップグレードは、データベースのバージョン番号をインクリメントした後の問題点を打ったときに試してみ
function delDB() {
var dbreq = indexedDB.deleteDatabase("HSC_Member_Database");
try{
dbreq.onsuccess = function (event) {
var output = document.getElementById("printOutput");
output.innerHTML = "deleted";
}
dbreq.onerror = function (event) {
console.log("Database error code: " + event.target.errorCode);
}
}catch(e){
console.log("Database error code: " + e.target.errorCode);
}
}