问题
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