I am storing key value using PersistentMap of near-sdk-as and Now I want to iterate over all the keys and values, is it possible ?
PS: The PersistentMap interface given in near-docs contains only get , set and other basic methods.
I am storing key value using PersistentMap of near-sdk-as and Now I want to iterate over all the keys and values, is it possible ?
PS: The PersistentMap interface given in near-docs contains only get , set and other basic methods.
Copyright © 2021 Jogjafile Inc.
This is currently not possible. You would have to store the keys in a separate array, maybe using
PersistentVector
. Then, you can iterate over the keys in thePersitentVector
, and get the values from thePersistentMap
.Here's an (incomplete) example on how you could do it.
There's also a note in the implementation for PersistentMap
Here are the available functions for
PersistentMap
. APersistentMap
is basically a helper collection for using the existing storage. You give thePersistentMap
a unique prefix, and when you useset(key)
the Map will create another unique key, combining the prefix with the key passed toset(key)
. It's just a convenient way of using the existing storage.