首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DexieJS在嵌套查询中返回NotFoundError

DexieJS在嵌套查询中返回NotFoundError
EN

Stack Overflow用户
提问于 2020-08-10 15:12:44
回答 1查看 31关注 0票数 0

当我有一个嵌套查询时,我在DexieJS上遇到了一个问题。以下是我的代码示例:

代码语言:javascript
复制
    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上工作,我毫不怀疑它应该能工作。

敬请指教,谢谢提前告知。

EN

回答 1

Stack Overflow用户

发布于 2020-08-10 15:28:44

找到了解决方案或变通方法,现在正在运行。

代码语言:javascript
复制
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在查询结果中进行查询。我希望这是正确的方式,并希望这会有所帮助。如果这不是正确的方式,请不要犹豫评论。

纳梅斯特。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63335636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档