【发布时间】:2020-11-17 15:21:19
【问题描述】:
我有一个thymeleaf 页面,在表格中显示数据库内容(人员)。
<tr id="tableBody">
<td th:text="${row.id}"/>
<td th:text="${row.firstname}"/>
<td th:text="${row.lastname}"/>
<td>
<button data-toggle="modal" data-target="#editModal" th:data-row="${row}">DEL</button>
</td>
</tr>
最后一列应该是删除该行的按钮。但在此之前,显示一个模式对话框,其中包含正在删除的数据。
问题:如何将整行人员对象传递给模态对话框?
我开始如下,但我错过了如何将人员对象从单击的行传递到模态对话框作为对象(这样我就可以在模式对话框)。
以下是一种伪代码:
<div class id="editModal" ...>
<div class="modal-body">
<div class="modal-body">
You are about to delete: <div th:text="${row.firstname}"/> <div th:text="${row.lastname}"/>
<form action="#" th:action="@{/delete/{id}" th:object="${row}" method="delete">
<input type="text" hidden="true" th:field="${row.id}">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" th:href="@{/delete/{id}(id=${row.id})}" th:method="delete">Remove</button>
</div>
</div>
</div>
【问题讨论】:
-
您需要纯 html+tymeleaf 解决方案还是可以接受 javascript?
-
我更喜欢纯百里香的解决方案,没有js。