使用Dexie,我是否可以将表中的所有对象获取到其中数组字段具有特定值作为其元素之一的表中? [英] With Dexie, can I get all objects in a table where an array field has a specific value as one of its elements?

查看:92
本文介绍了使用Dexie,我是否可以将表中的所有对象获取到其中数组字段具有特定值作为其元素之一的表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中每个对象都有一个由字符串组成的字段:例如, {people:['John','Bob','Sue']} .我需要表中所有在 people 数组中具有"Sue"的对象.

I have a table where each object has a field that is an array of strings: for example, { people: ['John', 'Bob', 'Sue'] }. I need all objects in the table that have 'Sue' in the people array.

Dexie可以这样做吗?

Can Dexie do this?

推荐答案

是,使用 MultiEntry 索引就可以做到这一点.

Yes, using MultiEntry indexes you can do exactly that.

const db = new Dexie("testdb");
db.version(2).stores({
  groups: 'id, *people'
});

async function addRow() {
  await db.groups.add({id: 1, people: ['John', 'Bob', 'Sue']});
}

async function findSuesGroups() (
  return await db.groups.where('people').equals('Sue').toArray();
}

请参见 https://dexie.org/docs/MultiEntry-Index 上的其他示例.

这篇关于使用Dexie,我是否可以将表中的所有对象获取到其中数组字段具有特定值作为其元素之一的表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆