请考虑List
中的以下List
:
List<List<SubSection>> listOfSubSectionLists
在Thymeleaf 3.0.9 TEXT模板中,我需要两个相应的循环嵌套,如下所示:
模板:
[# th:each="ssList, iterStat : ${listOfSubSectionLists}"]
Title: Sub-Section [( ${ssList.iterStat.index+1} )]
[# th:each="subSection : ${ssList.**?**}"]
Name: [( ${subSection.name} )]
Address: [( ${subSection.address} )]
Phone: [( ${subSection.phone} )]
[/]
[/]
是否可以在上面的模板的第三行中获取内部列表?
答案 0 :(得分:0)
如果您的变量如前所述,则列表仅为ssList
。因此代码应为:
[# th:each="ssList, iterStat: ${listOfSubSectionLists}"]
Title: Sub-Section [( ${iterStat.count} )]
[# th:each="subSection: ${ssList}"]
Name: [( ${subSection.name} )]
Address: [( ${subSection.address} )]
Phone: [( ${subSection.phone} )]
[/]
[/]
一些注意事项:
iterStat
是它自己的变量(与ssList无关)。您无法使用表达式ssList.iterStat
来访问它。iterStat.count
等同于iterStat.index + 1