Indexeddb - 记录已成功添加,但索引缺少数据

问题描述 投票:0回答:1

使用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 })                    
  ));                                                                                 
};  

enter image description here

enter image description here

javascript indexeddb
1个回答
0
投票

我遇到了同样的问题,可以通过将索引属性的类型从 bool 更改为 string 来解决。

这应该有效:

await mappings.add({ store: 'store0', name: 'foo store', inUse: 'true' });

© www.soinside.com 2019 - 2024. All rights reserved.