Javascript 表未包含在父事务中-Dexie
我已经编写了两个函数来使用Dexie包装器操作indexedDB中的数据。这是更新方法:Javascript 表未包含在父事务中-Dexie,javascript,reactjs,indexeddb,dexie,Javascript,Reactjs,Indexeddb,Dexie,我已经编写了两个函数来使用Dexie包装器操作indexedDB中的数据。这是更新方法: updateRow(documentId, rowId, row) { this.db.transaction('rw', this.db.tableEntry, async () => { await this.db.tableEntry.where({ documentId: documentId,
updateRow(documentId, rowId, row) {
this.db.transaction('rw', this.db.tableEntry, async () => {
await this.db.tableEntry.where({
documentId: documentId,
rowId: rowId
}).modify({row: row})
}).catch(e => {
console.log(e)
});
}
此函数的工作原理与预期完全相同。以下函数在同一类中以相同的方式实现:
getAllByDocumentId(documentId, callBack) {
this.db.transaction('rw', this.db.tableEntry, async () => {
await this.db.tableEntry.where({
documentId: documentId,
}).toArray((entries)=>callBack(entries))
}).catch(e => {
console.log(e)
});
}
执行此方法会产生以下错误:
name: "SubTransactionError"
message: "Table tableEntry not included in parent transaction."
我怎样才能解决这个问题?错误背后的根本原因是什么?我发现原因是,其他调用类执行多个包含事务的函数。因此,这些异步函数与它们的事务重叠。由于这个原因,只有第一个函数调用成功。我使用的简单方法是在调用时延迟函数的执行
update(...);
setTimeout(getAllByDocumentId(...),200);
setTimeout(otherDBFunction(...),300);
然后它工作得很好