javascript - 使用 Dexie,我可以获取表中的所有对象,其中数组字段具有特定值作为其元素之一?
问题描述
我有一个表,其中每个对象都有一个字符串数组字段:例如,{ people: ['John', 'Bob', 'Sue'] }
. 我需要表中所有在people
数组中包含“Sue”的对象。
德西能做到吗?
解决方案
是的,使用MultiEntry索引您可以做到这一点。
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();
}
推荐阅读
- octave - Octave - 使用 textscan 功能读取数据时出错
- java - 从 html dom 中删除一些 html 标签
- mysql - 尽管一切看似准确,MYSQL 仍显示模糊的语法错误
- android - ViewModelFactory 需要
- java - 为什么 eclipse 在我写的行中显示错误 public static void main(String[] args)
- java - 如何修复 android 10 中的崩溃处理
- sql - 获得前 40% 的用户基础销售额
- html - 开发工具(移动)和移动设备之间的差异
- sql - 使用 SQL 按给定数据元素显示小计
- javascript - 生成动态 div 并检索输入元素的值