我有这个简单的示例代码:
var request = mozIndexedDB.open('MyTestDatabase');
request.onsuccess = function(event){
var db = event.target.result;
var request = db.setVersion('1.0');
request.onsuccess = function(event){
console.log("Success version.");
if(!db.objectStoreNames.contains('customers')){
console.log("Creating objectStore");
db.createObjectStore('customers', {keyPath: 'ssn'});
}
var transaction = db.transaction([], IDBTransaction.READ_WRITE, 2000);
transaction.oncomplete = function(){
console.log("Success transaction");
var objectStore = transaction.objectStore('customers');
};
};
};
我得到这个:
A mutation operation was attempted on a database that did not allow mutations." code: "6
在线
var objectStore = transaction.objectStore('customers');
无法弄清楚 - 我做错了什么?
最佳答案
您只能在版本更改事务中创建或删除对象存储
参见:https://developer.mozilla.org/en-US/docs/IndexedDB/IDBDatabase
关于javascript - 在 indexedDB 中检索数据时出现错误 "A mutation operation was attempted on a database that did not allow mutations.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7301064/