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

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

问题描述

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

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:

基本上是两个类:Glossary 和 Word.Glossary 包含一个包含 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() 标记为公开).

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直接在table中,tr直接在td).

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

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

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