Getting the id of an object added to an indexedDB object store

时光总嘲笑我的痴心妄想 提交于 2021-01-27 05:59:36

问题


Given a indexeddb database with one declared objectstore as:

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

When I add an new item with the add request:

var resp = objectStore.add(row)

How can I get the new id of this added item in the onsuccess function?

resp.onsuccess = function(e) { /* code to get the id of the added item */}

回答1:


You can find the inserted key in e.target.result.



来源:https://stackoverflow.com/questions/13492785/getting-the-id-of-an-object-added-to-an-indexeddb-object-store

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!