nested (double) loop with thymeleaf

£可爱£侵袭症+ 提交于 2019-12-12 11:58:28

问题


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

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

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..


回答1:


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).

You should try:

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

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



来源:https://stackoverflow.com/questions/19956493/nested-double-loop-with-thymeleaf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!