有人可以告诉我是否可以使用索引、openCursor 和 keyRange 对 indexeddb 对象存储执行不区分大小写的搜索...。
我可以区分大小写并设法使用 toUpperCase 函数实现某些东西,但是有很多不同的这是不可行的...
欢迎任何帮助...谢谢...尝试示例:
var transaction = db.transaction("products", IDBTransaction.READ_ONLY);
var store = transaction.objectStore("products");
var descIndex = store.index('Index1');
var boundKeyRangeUpper = IDBKeyRange.bound(request.term.toUpperCase(), (request.term.toUpperCase()+'Z'));
descIndex.openCursor(boundKeyRangeUpper).onsuccess = function (e)
更新
这就是我最终实现的内容:涵盖和可能性的四个范围,即 FA、fA、Fa、fa... 这仅在第一个字母上完成,即“F”
var boundKeyRangeUpper = IDBKeyRange.bound(term.toUpperCase(), term.toUpperCase()+'Z');
var boundKeyRangeUpper2 = IDBKeyRange.bound(term.toUpperCase(), term.toUpperCase()+'z');
var boundKeyRangeLower = IDBKeyRange.bound(term.toLowerCase(), term.toLowerCase()+'z');
var boundKeyRangeLower2 = IDBKeyRange.bound(term.toLowerCase(), term.toLowerCase()+'Z');
上面的搜索结果存储在另一个 objectStore 中,但它们的描述为大写,因此 FISH、FRUIT、FRESH SALAD...是大写的...到目前为止,这不是一个理想的解决方案,但是它可以工作并且可以快速满足我的需求...也许我们最终会得到不区分大小写的搜索,也许不会...