我的场景:
我有一个索引数据库页面,它检索多个文件(图片),每张图片旁边都有一个“删除文件”按钮。此外,每张图片旁边都有复选框,用于删除要删除的多个文件。“删除文件”按钮调用“deleteRecord”函数并将密钥传递给它......它可以很好地删除文件。但是,当批量删除按钮调用相同的“deleteRecord”函数进行批量删除并将密钥传递给它时,不会删除任何文件。'deleteRecord' 贯穿每个键并有一个 onsuccess 事件。但是,什么都没有被删除?
deleteFile 函数(这适用于单个按钮):
function deleteRecord (id) {
console.log('inside deleteRecord. id: ' + id);
var transaction = db.transaction("patient", "readwrite");
var objectStore = transaction.objectStore("patient");
var request = objectStore.delete(id);
request.onsuccess = function(evt) {
console.log("It's gone!");
};
它被成功调用:
inputBttn.onclick = function () {
var prompt = 'Are you sure you want to delete this record?'
answer = confirm(prompt);
if (answer) {
deleteRecord(key);
console.log('Key = ' + key + ' Record Deleted');
}
并且不成功:
function massDelete() {
console.log('inside massDelete');
var checkboxes = document.getElementsByName('c1');
var prompt = 'You are about to delete Multiple Records. Are you sure?'
var answer = confirm(prompt);
if (answer) {
console.log('Delete confirmed...starting mass delete');
for (var x = 0; x < checkboxes.length; x++) {
if (checkboxes[x].checked) {
var key = checkboxes[x].value;
console.log('checkbox value = ' + key);
deleteRecord (key);
}
};
任何关于为什么会发生这种情况的解释都将不胜感激。