gpt4 book ai didi

javascript - IndexedDB 游标在 iOS 上更新后未获取下一条记录

转载 作者:行者123 更新时间:2023-11-30 19:57:14 24 4
gpt4 key购买 nike

我曾尝试研究类似的案例,但没有什么能与我所经历的相符。请考虑以下事项:

var req = indexedDB.open("myDatabase", 1);
req.onupgradeneeded = function (evt) {
var objStore = evt.target.result.createObjectStore("customers", { keyPath: "ID", autoIncrement: true });
objStore.createIndex("fName", "fName", { unique: false });
objStore.createIndex("lName", "lName", { unique: false });
objStore.createIndex("country", "country", { unique: false });
var obj1 = { fName: "James", lName: "Smith", age: 25, country: "United States", reviewStatus: "pending" };
var obj2 = { fName: "Tim", lName: "Jones", age: 32, country: "Canada", reviewStatus: "pending"};
var obj3 = { fName: "James", lName: "Miller", age: 22, country: "United States", reviewStatus: "pending"};
var obj4 = { fName: "James", lName: "Thompson", age: 40, country: "United Kingdom", reviewStatus: "pending"};
var obj5 = { fName: "Joseph", lName: "Harris", age: 28, country: "Canada", reviewStatus: "pending"};
var obj6 = { fName: "James", lName: "Jackson", age: 30, country: "United States", reviewStatus: "pending"};
objStore.add(obj1);
objStore.add(obj2);
objStore.add(obj3);
objStore.add(obj4);
objStore.add(obj5);
objStore.add(obj6);
};
req.onsuccess = function (evt) {
var tx = this.result.transaction("customers", "readwrite");
var objStore = tx.objectStore("customers");
var index = objStore.index("fName");
var cnt = index.count(IDBKeyRange.only("James"));
cnt.onsuccess = function () {
console.log(cnt.result + " records with fName: James");
};
var cursor = index.openCursor(IDBKeyRange.only("James"));
cursor.onsuccess = function (e) {
var record = e.target.result;
if (record) {
var updateData = record.value;
updateData.reviewStatus = "reviewed";
//update some other fields

var updateReq = record.update(updateData);
console.log("updating record");
record.continue();
}
};
cursor.onerror = function () {
console.log("error using cursor");
};

tx.oncomplete = function () {
console.log("got to transaction oncomplete");
//do other work required once cursor updates done
};
tx.onerror = function () {
console.log("error in transaction");
};
};
req.onerror = function () {
console.log("error opening database");
};

我的数据库有 4 条 fName = "James"的记录。我使用 Chrome (v71) 首先对此进行测试并获得结果:

4 records with fName: James
updating record
updating record
updating record
updating record
got to transaction oncomplete

随后在 Firefox (v64)、Opera (v56) 和 Chrome for Android 上进行的测试都产生了这些预期结果。当我在 iOS (11.4) 上测试时,我得到了结果:

4 records with fName: James
updating record
got to transaction oncomplete

我没有收到任何控制台错误或我的 onerror 函数中的任何消息。我不明白为什么在 iOS 中只有第一条记录被更新而光标没有移动到其他记录。我的代码中是否存在我不知道的错误,或者这是 iOS 中的某种错误?

最佳答案

看起来这是 Safari 中的一个错误。我在这里提交了错误报告 https://bugs.webkit.org/show_bug.cgi?id=192987 - 希望他们能在不久的将来修复它!

关于javascript - IndexedDB 游标在 iOS 上更新后未获取下一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53840474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com