The continuePrimaryKey()
method of the IDBCursor
interface advances the cursor to the to the item whose key matches the key parameter as well as whose primariy key matches the primary key parameter.
A typical use case, is to resume the iteration where a previous cursor has been closed, without having to compare the keys one by one.
Calling this method more than once before new cursor data has been loaded - for example, calling continuePrimaryKey()
twice from the same onsuccess handler - results in an InvalidStateError
being thrown on the second call because the cursor’s got value flag has been unset.
cursor.continuePrimaryKey(key, primaryKey);
This method may raise a DOMException
of one of the following types:
Exception | Description |
---|---|
TransactionInactiveError | This IDBCursor's transaction is inactive. |
DataError | The key parameter may have any of the following conditions:
|
InvalidStateError | The cursor is currently being iterated or has iterated past its end. |
InvalidAccessError | The cursor's direction is not prev or next . |
here’s how you can resume an iteration of all articles tagged with 'javascript' since your last visit:
let request = articleStore.index("tag").openCursor(); let count = 0; let unreadList = []; request.onsuccess = (event) => { let cursor = event.target.result; if (!cursor) { return; } let lastPrimaryKey = getLastIteratedArticleId(); if (lastPrimaryKey > cursor.primaryKey) { cursor.continuePrimaryKey("javascript", lastPrimaryKey); return; } // update lastIteratedArticleId setLastIteratedArticleId(cursor.primaryKey); // preload 5 articles into the unread list; unreadList.push(cursor.value); if (++count < 5) { cursor.continue(); } };
Specification | Status | Comment |
---|---|---|
Indexed Database API (Second Edition) The definition of 'continuePrimaryKey()' in that specification. | Editor's Draft | Initial definition. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | ? | 10 moz 51.0 (51.0) | ? | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 51.0 (51.0) | ? | ? | ? |
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor/continuePrimaryKey