HTML5 How to determine when the IndexedDB cursor is at the end

I repeat through indexedDB data store adding data to JavaScript array. How can I determine when the cursor is at the end, so I can sort the array and act on it?

onsuccess is called when a row is retrieved from the cursor - is there another callback when the entire cursor has been moved?

+4
source share
1 answer

The result ( event.target.result ) of a successful cursor query is either a cursor object or null.

If event.target.result set, this is the cursor, and you can access event.target.result.value . You can then call event.target.result.continue() to move on to the next object, if any.

If event.target.result not specified, then there are no more objects.

To illustrate, the code from my project:

  var collectObjects = function (request, cb) { var objects = [] request.onsuccess = function (event) { if (!event.target.result) return cb(null, objects) cursor = event.target.result objects.push(cursor.value) cursor.continue() } request.onerror = function (event) { cb(event.target.error) } 
+5
source

Source: https://habr.com/ru/post/1481664/


All Articles