我正在创建一个HTML 5 Web应用程序,我在本地存储上使用索引数据库,我在HTML 5索引数据库中设置数据库版本时遇到问题
代码片段如下
try {
var request = iDB.open('travelDB', dbVersion);
request.onerror = function (event) { errorDisplay('Failed to open IndexedDB database.'); }
request.onsuccess = function (event) {
db = request.result; // set the global db variable
db.onerror = dbErrorHandler;
alert(db.version != dbNewVersion);
if (db.version != dbNewVersion) {
alert('game begins');
db.setVersion(dbNewVersion);
// var req = db.setAttribute(version, dbNewVersion);
alert('game ends');
req.onerror = function (event) { alert('version error: ' + event.target.errorCode); }
req.onsuccess = function (event) {
alert('Creating the object store');
var objectStore = db.createObjectStore('oTravel', { keyPath: 'id', autoIncrement: true });
objectStore.createIndex('traveler', 'ciTraveler', { unique: false });
}
}
}
} catch (e) {
dispError('Browser supports IndexedDB but didn\'t open the database. (' + e.message + ')');
}
答案 0 :(得分:0)
我相信setVersion已被弃用。只需为indexedDB.open指定一个较新的版本,并使用onupgradeneeded回调来执行升级。