使用indexeddb和idb Promise库。
我创建了一个名为
storeMappings
的对象存储以及索引 inUse
。然后我用一些记录填充商店。
除了一个问题之外,一切都按预期进行。索引
inUse
不显示任何数据。有什么想法吗?
const _addStoreMappings = async (db) => {
const mappings = db.createObjectStore('storeMappings', {
keyPath: 'id',
autoIncrement: true,
});
await mappings.createIndex('inUse', 'inUse');
await mappings.add({ store: `store0`, name: `foo store`, inUse: true });
Array.fromAsync({ length: 14 }, (_, i) => (
mappings.add({ store: `store${++i}`, name: '', inUse: false })
));
};
我遇到了同样的问题,可以通过将索引属性的类型从 bool 更改为 string 来解决。
这应该有效:
await mappings.add({ store: 'store0', name: 'foo store', inUse: 'true' });