diff --git a/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js b/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js index 367350914..ac77b6ceb 100644 --- a/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js +++ b/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js @@ -419,6 +419,25 @@ } } }); + } else if (options.index) { + index = store.index(options.index.name); + if (index) { + if (options.index.lower && options.index.upper) { + bounds = IDBKeyRange.bound(options.index.lower, options.index.upper); + } else if (options.index.lower) { + bounds = IDBKeyRange.lowerBound(options.index.lower); + } else if (options.index.upper) { + bounds = IDBKeyRange.upperBound(options.index.upper); + } else if (options.index.only) { + bounds = IDBKeyRange.only(options.index.only); + } + + if (typeof options.index.order === 'string' && options.index.order.toLowerCase() === 'desc') { + readCursor = index.openCursor(bounds, window.IDBCursor.PREV || "prev"); + } else { + readCursor = index.openCursor(bounds, window.IDBCursor.NEXT || "next"); + } + } } else { // No conditions, use the index if (options.range) { diff --git a/js/components.js b/js/components.js index 74b0f736d..1890ca14d 100644 --- a/js/components.js +++ b/js/components.js @@ -21777,6 +21777,25 @@ return jQuery; } } }); + } else if (options.index) { + index = store.index(options.index.name); + if (index) { + if (options.index.lower && options.index.upper) { + bounds = IDBKeyRange.bound(options.index.lower, options.index.upper); + } else if (options.index.lower) { + bounds = IDBKeyRange.lowerBound(options.index.lower); + } else if (options.index.upper) { + bounds = IDBKeyRange.upperBound(options.index.upper); + } else if (options.index.only) { + bounds = IDBKeyRange.only(options.index.only); + } + + if (typeof options.index.order === 'string' && options.index.order.toLowerCase() === 'desc') { + readCursor = index.openCursor(bounds, window.IDBCursor.PREV || "prev"); + } else { + readCursor = index.openCursor(bounds, window.IDBCursor.NEXT || "next"); + } + } } else { // No conditions, use the index if (options.range) {