IndexedDB 获取刚刚保存在Dexie中的值的键

js5cn81o  于 2022-12-09  发布在  IndexedDB
关注(0)|答案(1)|浏览(233)

我正在使用put()将一个值保存到Dexie(IndexedDB)数据库中,并且我立即需要知道这个新条目的键是什么。
下面是我的代码。我无法找到一个解决方案搜索与谷歌。谢谢!

let newDog = {
          armbandNumber: this.armbandMax,
          dogCallName: this.callName,
          dogRegName: this.regName,
          dogOwnerKey: this.dogOwner.value,
          dogOwner: this.dogOwner.label,
          dogCoOwner: this.dogCoOwner,
          dogHandler: this.dogHandler.value,
          dogBday: this.dogBday,
          dogBreed: this.dogBreed,
          dogHeight: this.dogHeight,
          dogVariety: this.dogVariety,
          dogSire: this.dogSire,
          dogDam: this.dogDam,
          dogBreeder: this.dogBreeder,
          akcNum: this.akcNum,
          bhaNum: this.bhaNum,
          dogGender: this.dogGenderModel,
          dateDogAdded: Date.now(),
          barnHuntLevel: this.bhLevelModel,
          barnHuntClassAB: this.bhLevelModelAB,
          dogHeightDivision: this.heightDivision,
          scentWorkLevel: this.swLevelModel,
          scentWorkClassAB: this.swLevelModelAB,
        }
        pawTapDB.dogTable.put(newDog)
mfuanj7w

mfuanj7w1#

https://dexie.org/docs/Table/Table.put()表示:
如果操作成功,则返回的Promise解析为表中存储对象时所用的键。
所以这样做:

const key = await pawTapDB.dogTable.put(newDog);

相关问题