[Contract] Solidity 遍历 mapping 的一种方式


 

思路:为需要遍历的 mapping 再准备一个 list,之后通过 for 循环遍历 list 取得 mapping 的 key。

 

mapping (address => uint) usersValue

mapping (uint => address) list

uint length = xx

for (uint i; i < length; i++) {

  usersValue[ list[i] ]

}

 

Ref:https://ethereum.stackexchange.com/questions/10915/could-mapping-data-structure-return-the-number-of-items-it-points

Link:https://www.cnblogs.com/farwish/p/12364291.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM