这可能听起来很简单,但是我很难解决如何使用自定义元素/键和值配对迭代地图并仅打印姓氏。任何建议都会受到欢迎!
def map = ['user1':[firstname:'mark',surname:'spencer',role:"developer"],
['user2':[firstname:'mark',surname:'melony',role:"developer"]]
姓氏1:斯宾塞
姓氏2:melony
答案 0 :(得分:2)
这应该这样做
def map = [ 'user1':[firstname:'mark',surname:'spencer',role:"developer"],
'user2':[firstname:'mark',surname:'melony',role:"developer"] ]
map.eachWithIndex { key, map2, idx ->
println "surname ${idx + 1} - $map2.surname"
}