问题
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.
Can Dexie do this?
回答1:
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();
}
See other examples at https://dexie.org/docs/MultiEntry-Index
来源:https://stackoverflow.com/questions/60087180/with-dexie-can-i-get-all-objects-in-a-table-where-an-array-field-has-a-specific