我需要一个表格与标题一起显示,我有两个列表:
list1 = [A, B, C, D, E, F, G]
和list2
是地图列表
list2 = [ [from: A, to: A, val:20],
[from: A, to: B, val:10],
[from: A, to: C, val:30],
[from: B, to: A, val:10],
[from: B, to: B, val:40] ]
结果应为
from to A B C D E F G
A 20 10 30 - - - -
B 10 40 - - - - -
C - - - - - - -
D - - - - - - -
E - - - - - - -
F - - - - - - -
G - - - - - - -
我该怎么做?
答案 0 :(得分:0)
<table>
<tr>
<th>from</th>
<th>to</th>
<g:each in="${list1}" var="item">
<th>${item}</th>
</g:each>
</tr>
<g:each in="${list1}" var="fromItem">
<tr>
<td>${fromItem}</td>
<td></td>
<g:each in="${list1}" var="toItem">
<td>
${list2.find{it.from==fromItem && it.to==toItem}?.val?:"-"}
</td>
</g:each>
</tr>
</g:each>
</table>