admin管理员组文章数量:1399770
I am iterating thru an indexedDB data store, adding data to a JavaScript array. How can I tell when the cursor is at the end, so I can sort the array and act on it?
onsuccess is called when a row has been retrieved from the cursor - is there another callback when the entire cursor has been navigated?
I am iterating thru an indexedDB data store, adding data to a JavaScript array. How can I tell when the cursor is at the end, so I can sort the array and act on it?
onsuccess is called when a row has been retrieved from the cursor - is there another callback when the entire cursor has been navigated?
Share Improve this question edited Jan 13, 2022 at 20:37 General Grievance 5,04338 gold badges37 silver badges56 bronze badges asked May 19, 2013 at 20:58 ed4beckyed4becky 1,6302 gold badges21 silver badges58 bronze badges1 Answer
Reset to default 9The result (event.target.result
) of a successful cursor request is either a cursor object or null.
If event.target.result
is set, it's the cursor, and you can access event.target.result.value
. You can then call event.target.result.continue()
to go on to the next object, if any.
If event.target.result
is not set, then there are no more objects.
For illustration, some code from a project of mine:
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)
}
本文标签: javascriptHTML5 How to tell when IndexedDB cursor is at endStack Overflow
版权声明:本文标题:javascript - HTML5 How to tell when IndexedDB cursor is at end - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744175300a2593971.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论