gpt4 book ai didi

javascript - indexeddb 调用堆栈出现无效状态错误?

转载 作者:行者123 更新时间:2023-12-03 07:30:30 25 4
gpt4 key购买 nike

我再次有一些关于indexeddb的问题。我得到一个

InvalidStateError: A Mutation operation was attempted on a database that did not allow mutations.

还有一个

AbortError

这是我的代码:

DB_LINK.prototype.pushStoreNumeric = function () 
{
// Saving Values
var _temp = 0;
var _version = this.link.version;
var _name = this.link.name;
var that = this;
var _objectStoreNames = this.link.objectStoreNames;

// Close DB
this.link.close();
this.state = 4;

// Reopen Database
this.req = indexedDB.open(_name,_version+1); // Abort error here
this.req.onupgradeneeded = function () {
that.state = 1;


// Get Number of object stores
_temp = _objectStoreNames.length;

if(_temp != 0)
{
// Already object stores: read highest value
_temp = parseInt(_objectStoreNames[_objectStoreNames.length - 1]);
}
that.link.createObjectStore(_temp); // InvalidStateError here
};

我已标记了每条评论中发生错误的位置。

首先发生 InvalidStateError,随后发生 AbortError。

我在同一数据库的另一个 onsuccess 函数中调用此函数。这可能是问题所在吗?

最佳答案

什么是this.link?这可能就是问题所在。您需要对 indexedDB.open 请求创建的数据库实例执行 createObjectStore 操作。因此,无论是 this.req.result.createObjectStore 或(如果您更改为 this.req.onupgradeneeded = function (e) {),您都可以使用 e.target .result.createObjectStore.

更一般地说,我无法真正评论您的代码应该做什么,因为我只能看到一个片段,但每次调用时您如何增加版本看起来真的很奇怪。也许你实际上并不想这样做。您可能想阅读更多文档。

关于javascript - indexeddb 调用堆栈出现无效状态错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35821851/

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