在我的indexedDB数据库中,我需要在一个特定条目上打开一个游标,因为我想在该条目上调用游标的update
函数来更新存储在那里的对象的属性。
我当前的实现是迭代对象存储,直到光标指向具有给定键的对象,但由于我已经知道要查找的对象的键,因此迭代所有条目似乎相当浪费,当我也可以通过 key 得到它时。
有没有办法在查询结果上打开游标,例如objectstore.get(_key_).openCursor()
?
注意:我知道我也可以使用 objectstore.put(...)
来更新特定值,但我尝试避免这种情况,因为如果有新条目,这将是一个主要问题已创建。
最佳答案
您可以执行objectStore.openCursor(_key_)
,where _key_
is :
A key or IDBKeyRange to be queried. If a single valid key is passed, this will default to a range containing only that key. If nothing is passed, this will default to a key range that selects all the records in this object store.
关于javascript - IndexedDB:在特定条目上打开游标而不进行迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56832160/