获取添加到indexedDB对象存储库的对象的ID [英] Getting the id of an object added to an indexedDB object store

查看:49
本文介绍了获取添加到indexedDB对象存储库的对象的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

如何在成功功能中获取此添加项的新ID?

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

推荐答案

您可以在e.target.result中找到插入的密钥.

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

这篇关于获取添加到indexedDB对象存储库的对象的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆