在grails中呈现二维表的最佳方法
我需要一个表来显示from和to标题,我有两个列表:在grails中呈现二维表的最佳方法,grails,Grails,我需要一个表来显示from和to标题,我有两个列表: 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]
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 - - - - - - -
我该怎么做?
<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>
从…起
到
${item}
${fromItem}
${list2.find{it.from==fromItem&&it.to==toItem}?.val?:“-”}
通过在列表1上迭代,我可以打印列标题和行标题,但对于数据,我不确定如何在特定单元格中显示值,另一个重要的是,这些是可编辑字段,我应该能够保存数据