我有一个包含页面上各种元素属性的IndexedDB。我对这些属性之一有一个索引,我使用一个键范围来获得特定的结果列表。等待IDBCursor.onsuccess完成
var key = IDBKeyRange.bound(10, 20);
var cursor = store.index('property').openCursor(key);
我现在的问题是与cursor.onsuccess
函数。它似乎对结果集中的每个结果执行。因此,一旦解析了所有结果,我就无法执行回调函数。
cursor.onsuccess = function (e) {
var cursor = e.target.result;
if (cursor) {
if (cursor.value.prop1 > 30 && cursor.value.prop2 < 80) {
// Do stuff with result
someArray.push({
prop1: cursor.value.prop1,
prop2: cursor.value.prop2
}):
}
}
cursor.continue();
};
我最初尝试过这个,但'cursor.oncomplete'永远不会触发(至少在Chrome 23.0.1271.26中) –
游标对象没有完成事件,您应该将此事件绑定到事务对象。 –
我想我不明白...变量'游标'代表事务'openCursor()'...我不知道还有什么我会绑定'oncomplete'函数... –