【问题标题】:Thymeleaf 3 syntax to iterate List<List<T>>Thymeleaf 3 语法迭代 List<List<T>>
【发布时间】:2019-05-08 06:14:20
【问题描述】:

考虑以下ListList

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} )]
    [/]
[/]

是否可以在上面的模板中获取第三行的内部列表?

【问题讨论】:

    标签: java arraylist thymeleaf


    【解决方案1】:

    如果您的变量与描述的一样,那么列表就是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

    【讨论】:

    • 我把它弄得太复杂了
    猜你喜欢
    • 2013-10-31
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多