【问题标题】:How can I index and query nested arrays in Dexie.js?如何在 Dexie.js 中索引和查询嵌套数组?
【发布时间】:2021-08-11 15:40:32
【问题描述】:

MultiEntry 索引的文档说可以使用任何Indexable Type

数组是可索引的类型。因此应该可以索引数组的数组等等,对吧?

但是,我找不到任何示例或弄清楚如何查询这些示例。

基本上,我想要的是这样的:

var db = new Dexie('dbname');

db.version(1).stores({
  books: 'id, author, name, *properties'
});

db.books.put({
  id: 1,
  name: 'Human Action', 
  author: 'Ludwig von Mises',
  properties: [['language', 'english'], ['subject', 'philosophy'], ['subject', 'economics']]
});

然后能够找到具有economics 主题的书。

【问题讨论】:

    标签: dexie


    【解决方案1】:

    没错。属性数组中的每个条目都是一个包含两个字符串的数组 - 内部数组本身是可索引的,并且可以充当可索引条目。

    所以要查找所有具有学科经济学的书籍,请这样做

    db.books.where({properties: ['subject', 'economics']}).toArray()
    

    或等效形式:

    db.books
      .where('properties')
      .equals(['subject', 'economics'])
      .toArray();
    

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 2019-12-12
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      相关资源
      最近更新 更多