我只是想通了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>
Thymeleaf th:field
生成3个html属性id
,name
和value
。
对于您的情况,使用th:field
,th:id
和th: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"/>