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

标签 indexeddb

给定一个带有一个声明对象存储的 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/

相关文章:

javascript - 德克西JS : very large IndexedDB but empty tables

javascript - 无法读取未定义 IndexedDB 的属性 'result'

couchdb - 删除 pouchDB 中的所有冲突

html - IndexedDB 在 FireFox 和 IE 中不工作

google-chrome-extension - 与 WebSQL 相比,IndexedDB 非常慢,我做错了什么?

javascript - indexedDB 添加记录到 objectStore 只能工作一次

database - 在索引数据库中升级数据库版本时,在 firefox 操作系统中会出现错误。 "A request was aborted, for example through a call to IDBTransaction.abort."

javascript - 模拟/填充索引数据库

javascript - 在 Firefox 中检查 IndexedDB 的真实可用性

javascript - var result = wait someFunc() 返回一个对象,但我期望对象列表