gpt4 book ai didi

indexeddb - 获取添加到 indexedDB 对象存储的对象的 id

转载 作者:行者123 更新时间:2023-12-03 21:56:55 26 4
gpt4 key购买 nike

给定一个带有一个声明对象存储的 indexeddb 数据库:

var objectStore = thisDb.createObjectStore("table", {keyPath: "id", autoIncrement: true})

当我使用添加请求添加新项目时:
var resp = objectStore.add(row)

如何在 onsuccess 函数中获取此添加项的新 ID?
resp.onsuccess = function(e) { /* code to get the id of the added item */}

最佳答案

您可以在 e.target.result 中找到插入的键。

关于indexeddb - 获取添加到 indexedDB 对象存储的对象的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13492785/

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