当我有一个嵌套查询时,我在DexieJS上遇到了一个问题。以下是我的代码示例:
let id = 1;
let child = db.child.where({ id : result.child_id }).first( item => item ).catch( e => "NotFoundError"; );
console.log(child); // success, it shows the child item
db.parent.where({ id : id }).each( parent => {
let child = db.child.where({ id : parent.id }).first( item => item ).catch( e => "NotFoundError"; );
console.log(child); // it will show NotFoundError
});不知道发生了什么,嵌套查询不能在DexieJS上工作,我毫不怀疑它应该能工作。
敬请指教,谢谢提前告知。
发布于 2020-08-10 15:28:44
找到了解决方案或变通方法,现在正在运行。
await db.transaction('r', db.parent, db.child, async () => {
await db.parent.where({ id : id }).each( async parent => {
let child = db.child.where({ parent_id : parent.id }).first( result => result );
console.log(child) // *now it shows the child record
});
});看起来我们需要使用transaction在查询结果中进行查询。我希望这是正确的方式,并希望这会有所帮助。如果这不是正确的方式,请不要犹豫评论。
纳梅斯特。
https://stackoverflow.com/questions/63335636
复制相似问题