我如何迭代所有商店?
How do I iterate all stores?
我正在使用 localForage 并且正在使用 localforage.createInstance
创建一堆不同的商店。
现在我需要迭代这些商店。我无法跟踪创建了哪些商店,所以我需要 localForage 给我一份商店列表,但我在 API.
中找不到这样的东西
这可能吗?
不,不幸的是目前没有这样的东西可用。
Here is the issue 当前正在跟踪该请求。
我不确定这是否是最好的方法,但是...
github 中的问题已被遗忘。
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
我正在使用 localForage 并且正在使用 localforage.createInstance
创建一堆不同的商店。
现在我需要迭代这些商店。我无法跟踪创建了哪些商店,所以我需要 localForage 给我一份商店列表,但我在 API.
中找不到这样的东西这可能吗?
不,不幸的是目前没有这样的东西可用。 Here is the issue 当前正在跟踪该请求。
我不确定这是否是最好的方法,但是... github 中的问题已被遗忘。
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