This is how to create key range between the search term and the search term with a 'z' letter at the final.
db.transaction(['table'], 'readonly')
  .objectStore('table')
  .openCursor(
    IDBKeyRange.bound(searchTerm, searchTerm + '\uffff'), // The important part, thank Velmont to point out
    'prev')
  .onsuccess = function (e) {
    e || (e = event);
    var cursor = e.target.result;
    if (cursor) {
      // console.log(cursor.value.column1 + ' = ' + cursor.value.column2);
      cursor.continue();
    }
  };If you need to order the result, so I defined a array before the transaction, then we call it when we loaded all data, like this:
var result = []; db.transaction(['table'], 'readonly') .objectStore('table') .openCursor( IDBKeyRange.bound(searchTerm, searchTerm + '\uffff'), // The important part, thank Velmont to point out 'prev') .onsuccess = function (e) { e || (e = event); var cursor = e.target.result; if (cursor) { result.push([cursor.value.column1, cursor.value.sortcolumn]); cursor.continue(); } else { if (result.length) { result.sort(function (a, b) { return a[1] - b[2]; }); } // Process code here } };
Komentar
Posting Komentar