admin管理员组

文章数量:1430550

folks...

Can I do something like this using Thymeleaf?

<tr th:each="row : ${list}">
    <td th:each="field : ${arrayFieldName}" scope="row">
        <span th:text="|${row.${field[0]}}|"></span>
    </td>
</tr>

I can use:

<span th:text="|${row.nameOfMyField1}|"></span>
<span th:text="|${row.nameOfMyField2}|"></span>

that works fine... but in this case I need to perform the th:each for every field name that I have in ${arrayFieldName}.

How can I do this?

folks...

Can I do something like this using Thymeleaf?

<tr th:each="row : ${list}">
    <td th:each="field : ${arrayFieldName}" scope="row">
        <span th:text="|${row.${field[0]}}|"></span>
    </td>
</tr>

I can use:

<span th:text="|${row.nameOfMyField1}|"></span>
<span th:text="|${row.nameOfMyField2}|"></span>

that works fine... but in this case I need to perform the th:each for every field name that I have in ${arrayFieldName}.

How can I do this?

Share Improve this question asked Nov 19, 2024 at 13:27 gaplergapler 91 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Yes, this is called preprocessing in Thymeleaf. It should look like this:

<tr th:each="row : ${list}">
    <td th:each="field : ${arrayFieldName}" scope="row">
        <span th:text="|${row.__${field}__}|"></span>
    </td>
</tr>

本文标签: Thymeleaf and macro substitutionStack Overflow