- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
为什么会出现错误?
我的代码:
var idb = window.indexedDB || // Use the standard DB API
window.mozIndexedDB || // Or Firefox's early version of it
window.webkitIndexedDB; // Or Chrome's early version
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;
var dbName='nameDb';
var idbRequest=idb.open(dbName,'4.67' /*,dbDescription */);
idbRequest.onsuccess=function (e) {
debugger
var db=e.target.result;
if (!db.objectStoreNames.contains('chat')){
co=db.createObjectStore('chat',{'id':100});
};
if (!db.objectStoreNames.contains('iam')){
co1=db.createObjectStore('iam');
};
};
idbRequest.onerror = function (e) {
debugger
};
Uncaught InvalidStateError: Failed to execute 'createObjectStore' on 'IDBDatabase': The database is not running a version change transaction. index.html:37 idbRequest.onsuccess
最佳答案
您不能在 onsuccess
方法中创建 objectStore
。您只能在 upgradeneeded
事件中执行此操作。
引用自文档:
When you create a new database or increase the version number of an existing database (by specifying a higher version number than you did previously, when Opening a database), the
onupgradeneeded
event will be triggered. In the handler for this event, you should create the object stores needed for this version of the database
参见 documentation .
关于javascript - 无法在 'createObjectStore' 上执行 'IDBDatabase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24382085/
为什么会出现错误? 我的代码: var idb = window.indexedDB || // Use the standard DB API window.mozIn
我是一名优秀的程序员,十分优秀!