我正在使用localForage而我正在使用localforage.createInstance
创建一堆不同的商店。
现在我需要迭代这些商店。我无法跟踪哪些商店被创建,所以我需要localForage给我一个商店列表,但我在API中找不到这样的东西。
这可能吗?
答案 0 :(得分:1)
不幸的是,现在没有这样的东西。 当前跟踪该请求的Here is the issue。
答案 1 :(得分:0)
我不确定这是否是最好的方法,但是... github中的issue忘记了。
async function getStoreNames() {
//Create some stores with localforage
let store1 = await localforage.createInstance({
name: "yourDBName",
storeName: "store1"
});
let store2 = await localforage.createInstance({
name: "yourDBName",
storeName: "store2"
});
let store3 = await localforage.createInstance({
name: "yourDBName",
storeName: "store3"
});
await store1.setItem("aaa", "aaa")//add something on stores
await store2.setItem("bbb", "bbb")
await store3.setItem("ccc", "ccc")
//With store fully initialized (can be any in yourDBName) get the stores names, can be the blob test store.
//Filter names if needed.
let storeNames = Array.from(store1._dbInfo.db.objectStoreNames).filter(x => !x.startsWith("l"))
console.log(storeNames);
return storeNames;
}
getStoreNames()//Remember the store must be working