我已經陣列在常規的Groovy的findAll在陣列
def userList = [[name: user1, id:0, ip: 127.0.0.1], [name: user2, id:1, ip: 127.0.0.2], [name: user3, id:2, ip: 127.0.0.3]]
以下數組我遍歷另一個列表rows
的陣列和我想從基於索引上面的列表中提取的條目。
rows.eachWithIndex { row, index ->
groovy.lang.Closure idMatch = { it.id == index }
def match = userList.findAll(idMatch)
println(match)
}
匹配總是返回空。
當我打印它時,索引值正確顯示爲0,1,2等。
您的代碼對我的作品...... –
我的猜測是,'你id'' userList'不是'Integer' –
@tim_yates是否必須使用'it.id.toInteger()'? – user2133404