javascript - IDBKeyRange.only() returns only first matching record -


i querying database table follows:

function getallrecords(letter) {      var trans = db.transaction(["observablestates"],"readonly").objectstore("observablestates").index('letterindex');      //get matching records      var request = trans.opencursor(idbkeyrange.only([letter]));       request.onsuccess = function(event)      {           var cursor = event.target.result;           if(cursor)           {               count+=1;               cursor.continue();               console.log(cursor);           }        }        request.onerror = function(event)       {           console.log('error loading data table');       }       //delete of returned records 

}

i have 2 records having value of letter first record returned. cursor.continue() not seem work in case.

any appreciated. thanks

that should work, , can't reproduce problem. it's possible you're hitting browser bug (which browser testing in?) or there's incorrect assumption in code i'm not capturing here.

here's i'm doing:

var openrequest = indexeddb.open('test'); openrequest.onupgradeneeded = function() {   var db = openrequest.result;   var store = db.createobjectstore('observablestates');   store.createindex('letterindex', 'p');    store.put({p: ['a']}, 1);   store.put({p: ['a']}, 2); }; openrequest.onsuccess = function() {   var db = openrequest.result;   var trans = db.transaction('observablestates', 'readonly');   var index = trans.objectstore('observablestates').index('letterindex');   var request = index.opencursor(idbkeyrange.only(['a']));   request.onsuccess = function() {     var cursor = request.result;     if (cursor) {       console.log(cursor.key, cursor.primarykey);       cursor.continue();     }   } }; 

and see logged:

  • ["a"] 1
  • ["a"] 2

you may want count([letter]) request against index confirm have many records expect.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -