私は IndexedDB を使用しています。私は 2 つのオブジェクトストアを持っています。 、そのパーツが含まれる機器を表すフィールドtagNoを持つ)。
Equipmentのレコードを削除する場合、 equipPartsのtagNoを含むすべてのレコードを削除したいと思います(「 whereequipParts.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 = function() {
alert("Deletion attempt NG");
}
var ereq = estore.delete(tagno);
ereq.onsuccess = function(e) {
alert("Form deletion OK");
window.location = "index.html";
}
ereq.onerror = function(e) {
alert("Form deletion NG");
window.location = "index.html";
}
db.close();
問題は、equipのレコードのみが削除されることです。equipPartsのレコードはそこに残ります。一意ではないインデックス (親オブジェクト ストアの主キーになる可能性があります) に基づいて、IndexedDB オブジェクト ストア内の複数のレコードを削除する方法はありますか?