简体   繁体   English

未捕获的 DOMException:无法在“IDBObjectStore”上执行“放置”:评估 object 存储的密钥路径在 request.onsuccess 处未产生值

[英]Uncaught DOMException: Failed to execute 'put' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value at request.onsuccess

I'm trying to Store some application data using indexedDB我正在尝试使用 indexedDB 存储一些应用程序数据

Here is my code这是我的代码

function _getLocalApplicationCache(_, payload) {
const indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.shimIndexedDB;
if (!indexedDB) {
    if (__DEV__) {
        console.error("IndexedDB could not found in this browser.");
    }
}

const request = indexedDB.open("ApplicationCache", 1);
request.onerror = event => {
    if (__DEV__) {
        console.error("An error occurred with IndexedDB.");
        console.error(event);
    }
    return;
};

request.onupgradeneeded = function () {
    const db = request.result;
    const store = db.createObjectStore("swimlane", {keyPath: "id", autoIncrement: true});
    store.createIndex("keyData", ["name"], {unique: false});
};

request.onsuccess = () => {
    // creating the transition
    const db = request.result;
    const transition = db.transaction("swimlane", "readwrite");

    // Reference to our object store that holds the swimlane data;
    const store = transition.objectStore("swimlane");
    const swimlaneData = store.index("keyData");

    payload = JSON.parse(JSON.stringify(payload));
    store.put(payload);

    const Query = swimlaneData.getAll(["keyData"]);

    Query.onsuccess = () => {
        if (__DEV__) {
            console.log("Application Cache is loaded", Query.result);
        }
    };
    transition.oncomplete = () => {
        db.close();
    };
};

} }

If I do use different version then 1 here --> indexedDB.open("ApplicationCache", 1);如果我确实使用不同的版本,那么这里是 1 --> indexedDB.open("ApplicationCache", 1); I'm getting a error like they keyPath is already exist.我收到一个错误,就像他们的 keyPath 已经存在一样。 And other than than for version 1 I'm getting this error.除了版本 1 之外,我收到了这个错误。

Can someone please help me where i'm doing wrong.有人可以在我做错的地方帮助我。

  • Review the introductory materials on using indexedDB.查看有关使用 indexedDB 的介绍性材料。
  • If you did something like connect and create a database without a schema, or created an object store without an explicit key path, and then you stored some objects, and then you edited the upgradeneeded callback to specify the keypath, and then never triggered the upgradeneeded callback to run because you continue to use current version number instead of a newer version number, it would be one possible explanation for this error.如果您执行了诸如连接并创建没有模式的数据库之类的操作,或者创建了没有显式密钥路径的 object 存储,然后存储了一些对象,然后您编辑了 upgradeneeded 回调以指定密钥路径,然后从未触发 upgradeneeded回调运行,因为您继续使用当前版本号而不是较新的版本号,这将是此错误的一种可能解释。
  • The upgradeneeded callback needs to have logic that checks for whether the object stores and indices already exist, and only create them if they do not exist. upgradeneeded 回调需要具有检查 object 存储和索引是否已存在的逻辑,并且仅在它们不存在时创建它们。 If the store does not exist, create it and its indices.如果商店不存在,则创建它及其索引。 If the store exists and the indices do not, add indices to the store.如果存储存在而索引不存在,则将索引添加到存储。 If the store exists and the indices exist, do nothing.如果存储存在并且索引存在,则什么也不做。
  • You need to trigger the upgradeneeded callback to run after changing your database schema by connecting with a higher version number.您需要通过连接更高的版本号来触发 upgradeneeded 回调以在更改数据库架构后运行。 If you do not connect with a higher version number, the callback never runs, so you will end up connecting to the older version where your schema changes have not taken place.如果您不连接更高的版本号,则回调永远不会运行,因此您最终将连接到未发生架构更改的旧版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法存储数据 IndexedDB(无法在“IDBObjectStore”上执行“添加”:评估 object 存储的键路径未产生值) - Cannot Store Data IndexedDB (Failed to execute 'add' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value) 如何修复索引数据库中的错误“无法在'IDBObjectStore'上执行'add':评估object存储的键路径没有产生值。” - How can I fix the error in indexed DB "Failed to execute 'add' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value. " 无法在“ IDBObjectStore”上执行“ put”:无法克隆对象 - Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned IndexedDB错误:未捕获的DataCloneError:无法在“ IDBObjectStore”上执行“ put”:无法克隆对象 - IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned DOMException:无法在“IDBObjectStore”上执行“getAll”:事务在 angular 中不活动 - DOMException: Failed to execute 'getAll' on 'IDBObjectStore': The transaction is not active in angular 未能在“IDBObjectStore”上执行“放置”:事务已完成 - Failed to execute 'put' on 'IDBObjectStore': The transaction has finished 未捕获的 DOMException:无法在“Window”上执行“postMessage”:无法克隆对象 - Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned 无法在“IDBObjectStore”上执行“添加” - Failed to execute 'add' on 'IDBObjectStore' 错误并且没有相同代码的错误:无法在'IDBObjectStore'上执行'put' - Error and no error with the same code: Failed to execute 'put' on 'IDBObjectStore' 未捕获的 DOMException:无法在“节点”上执行“appendChild” - Uncaught DOMException: Failed to execute 'appendChild' on 'Node'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM