百里香嵌套(双)循环 [英] nested (double) loop with thymeleaf

查看:69
本文介绍了百里香嵌套(双)循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索现有答案,但找不到.

I've tried searching for existing answers, but I could not find them.

我想从ArrayList中的对象访问ArrayList,所以:

I'd like to access an ArrayList from an object within an ArrayList, so:

基本上有两个类:词汇表和Word. 词汇表包含一个包含Word对象的列表,Word类包含一个包含更多Word对象(相关单词)的列表

Basically two classes: Glossary and Word. Glossary contains a list with Word objects, the class Word contains a list with more Word objects (related words)

<table>
<span th:each="word : ${glossary.words}">
 <td>
  <tr th:each="relatedWord: ${word.relatedWords}">
    <p th:text="${relatedWord.getName()}"></p>
  </tr>
 <td>
</span>
</table>

不幸的是,这对我不起作用.

Unfortunately this does not work for me..

推荐答案

我不确定,但是我不认为您可以像访问公共非静态getter一样(假设getName()被标记为public).

I'm not sure but I don't think you can access public non-static getters like you do (assuming getName() is marked as public).

您应该尝试:

<table>
    <span th:each="word : ${glossary.words}">
        <td>
            <tr th:each="relatedWord: ${word.relatedWords}">
                <p th:text="${relatedWord.name}"></p>
            </tr>
        <td>
    </span>
</table>

一个注意事项:上面的代码绝对不是有效的XHTML(span内部直接为spantd内部直接为tr).

One note: the above code is absolutely not valid XHTML (span directly inside table, tr directly inside td).

这篇关于百里香嵌套(双)循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆