Thymeleaf th:字段覆盖th:值

问题描述 投票:0回答:1

我只是想通了th:field属性覆盖了th:value属性。

在我的th:each中,我想要覆盖th:field为我生成的值。有谁知道如何实现这一目标?

提前致谢。

<ul id="userGroupContainer">
	<li class="clickable unselected" th:each="u, rowStat : ${userNotInGroup}" th:if="${u.id}">
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].id}" th:value="${u.id}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].displayName}" th:value="${u.displayName}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="* {users[__${rowStat.index}__].username}" th:value="${u.username}" />
      <input type="text" readonly="readonly" hidden="hidden" disabled="disabled" th:field="*{users[__${rowStat.index}__].emailAddress}" th:value="${u.emailAddress}" />
								<span th:text="${u.displayName}"></span>
	</li>
</ul>
java html thymeleaf
1个回答
5
投票

Thymeleaf th:field生成3个html属性idnamevalue

对于您的情况,使用th:fieldth:idth:name而不是使用th:value,如下所示。

<input type="text" th:id="${'users'+__${rowStat.index}__+'.id'}" th:name="${'users['+__${rowStat.index}__+'].id'}" th:value="${u.id}" readonly="readonly" hidden="hidden" disabled="disabled"/>
<input type="text" th:id="${'users'+__${rowStat.index}__+'.displayName'}" th:name="${'users['+__${rowStat.index}__+'].displayName'}" th:value="${u.displayName}" readonly="readonly" hidden="hidden" disabled="disabled"/>
© www.soinside.com 2019 - 2024. All rights reserved.