【发布时间】:2017-10-05 12:42:48
【问题描述】:
我正在使用 localForage,我正在使用 localforage.createInstance 创建一堆不同的商店。
现在我需要迭代这些商店。我无法跟踪创建了哪些商店,因此我需要 localForage 为我提供商店列表,但我在 API 中找不到类似的内容。
这可能吗?
【问题讨论】:
标签: localforage
我正在使用 localForage,我正在使用 localforage.createInstance 创建一堆不同的商店。
现在我需要迭代这些商店。我无法跟踪创建了哪些商店,因此我需要 localForage 为我提供商店列表,但我在 API 中找不到类似的内容。
这可能吗?
【问题讨论】:
标签: localforage
我不确定这是否是最好的方法,但是... 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
【讨论】:
不,不幸的是,目前没有类似的东西可用。 Here is the issue 当前跟踪该请求。
【讨论】: