我正在使用 put() 将一个值保存到我的 Dexie (IndexedDB) 数据库中,并且我立即需要知道该新条目的键是什么。我该如何去做呢?
下面是我的代码。我无法通过 Google 搜索找到解决方案。谢谢!
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)
最佳答案
https://dexie.org/docs/Table/Table.put()说:
If the operation succeeds then the returned Promise resolves to the key under which the object was stored in the Table.
这样做:
const key = await pawTapDB.dogTable.put(newDog);
关于indexeddb - 获取刚刚保存在 Dexie 中的 key 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72382645/