小编use*_*708的帖子

基于索引删除IndexedDB中的多个记录

我使用的是IndexedDB,我有两个对象存储:equip(代表不同的设备,主键tagNo)和equipParts(代表一个设备的部分,并且有一个基于标签号/序列号的索引,主键seqNo,带有字段tagNo,表示该部分所属的设备).

如果我删除一条记录装备,我想删除所有记录equipParts轴承TAGNO装备(就像"里equipParts.tagNo = equip.tagNo").

摘自我的代码:

var tx = db.transaction(["equip", "equipParts"],"readwrite");
var estore = tx.objectStore("equip");
var pstore = tx.objectStore("equipParts");
var tagIndex = pstore.index("by_tagNo");
var pdestroy = tagIndex.openCursor(IDBKeyRange.only(tagno)); //opens all records bearing the selected tag number
pdestroy.onsuccess = function() {
    var cursor = pdestroy.result;
    if (cursor) {
        if (cursor.value.tagNo == tagno) {
            pstore.delete(cursor.value.seqNo); //I guess I'm wrong here
        }
        cursor.continue;
    }
}
pdestroy.onerror = …
Run Code Online (Sandbox Code Playgroud)

indexing cursor indexeddb

13
推荐指数
1
解决办法
8918
查看次数

标签 统计

cursor ×1

indexeddb ×1

indexing ×1