通过多个键从indexedDB获取所有数据

通过多个键从indexedDB获取所有数据,indexeddb,Indexeddb,如何通过2个或更多键从indexedDB获取数据? 例如,我有一个images\u存储,其中images\u代码作为索引。 假设我有: image_code | image_value img_aaa000 | ########### img_bbb111 | #######$$.# img_ccc222 | ###5%###### img_ddd333 | #.###***### 我想获取图像代码“img_bbb111”和“img_ddd333”的数据,就像我从SQL查询它一样: SELEC

如何通过2个或更多键从indexedDB获取数据? 例如,我有一个images\u存储,其中images\u代码作为索引。 假设我有:

image_code | image_value
img_aaa000 | ###########
img_bbb111 | #######$$.#
img_ccc222 | ###5%######
img_ddd333 | #.###***###
我想获取图像代码“img_bbb111”和“img_ddd333”的数据,就像我从SQL查询它一样:

SELECT * FROM images_store WHERE image_code IN ("img_bbb111","img_ddd333");

谢谢

您需要发出多个查询。中的SQL
操作符本质上是
image\u code=a或image\u code=b
的语法糖。这里的问题是如何使用
。indexedDb不支持类似于
的内容。因此,您需要先查询
img_bbb111
,然后再查询
img_ddd333
,然后将两个查询的结果合并

大概是这样的:

函数myOnUpgradeNeeded(事件){
const imageStore=db.createObjectStore('images_store',…);
createIndex('image\u code\u index','image\u code');
}
函数findImage循环码(数据库、代码){
返回新承诺((解决、拒绝)=>{
const transaction=db.transaction('images_store');
const store=transaction.objectStore('images_store');
const code index=store.index('image_code_index');
常量结果=[];
transaction.oncomplete=event=>resolve(结果);
transaction.onerror=event=>reject(event.target.error);
for(代码的常量代码){
const request=codeIndex.get(代码);
request.onsuccess=onRequestSuccess;
}
函数onRequestSuccess(事件){
const image=event.target.result;
如果(图像){
结果:推送(图像);
}
}
});

}
谢谢Josh!是的,看来IDB不支持。在本例中,我将使用多个IDB.get()。