我想删除带索引的数据,但我得到错误。如果我直接删除没有索引的对象存储,没有问题,但我需要的是删除带索引。
Database screenshot
创建数据库函数
var objectStore = db.createObjectStore("rooms", { keyPath: "id", autoIncrement: true });
let index = objectStore.createIndex('floorIndex', ['floorIndex']);
删除函数
var floorIndexValue = "2";
const request = window.indexedDB.open("AdminDatabase");
request.onsuccess = (event) => {
const db = event.target.result;
const txnRoom = db.transaction('rooms', 'readwrite');
const storeRoom = txnRoom.objectStore('rooms');
const index = storeRoom.index('floorIndex');
let query = index.delete([floorIndexValue]);
query.onerror = function (event) {
console.log(" Room Delete Error DB: " + event);
};
query.onsuccess = function (event) {
console.log(" Room Delete Succes DB: " + event);
};
};
1条答案
按热度按时间eanckbw91#
我在这里解决了IDBKeyRange的问题: