gpt4 book ai didi

javascript - 在 indexedDB 中检索数据时出现错误 "A mutation operation was attempted on a database that did not allow mutations."

转载 作者:数据小太阳 更新时间:2023-10-29 06:13:16 27 4
gpt4 key购买 nike

我有这个简单的示例代码:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com