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