我正在使用百里香来显示对象列表,如下所示:
<tr th:each="Reports : ${report}">
<td><span th:text="${Reports.id}">Id</span> </td>
<td><span th:text="${Reports.description}">Description</span></td>
<td><span th:text="${Reports.entity}">Entity</span></td>
<td><span th:text="${Reports.long}">Long</span></td>
<td><span th:text="${Reports.lat}">Lat</span></td>
<td><span th:text="${Reports.type}">Type</span></td>
<td><span th:text="${Reports.solved}">Solved</span></td>
<div class="btn-group">
<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Azione</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Solved</a> <div class="dropdown-divider"></div>
<a href="" class="dropdown-item">Not Solved</a>
</div>
</div>
</td>
</tr>
当然可以。现在,我需要使用从每一行中存在的按钮获取的值来修改“已解决”的值,因此我只需要将id(这是我的主要键)和按钮值通过发布发送到另一个url。我该如何实现?
答案 0 :(得分:1)
<form th:action="@{'/posturl/'}" method="post">
<tr th:each="Reports : ${report}">
<td><span th:text="${Reports.id}" th:value="${Reports.id}">Id</span> </td>
<td><span th:text="${Reports.description}" th:value="${Reports.id}">Description</span></td>
<td><span th:text="${Reports.entity}" th:value="${Reports.id}">Entity</span></td>
<td><span th:text="${Reports.long}" th:value="${Reports.id}">Long</span></td>
<td><span th:text="${Reports.lat}" th:value="${Reports.id}">Lat</span></td>
<td><span th:text="${Reports.type}" th:value="${Reports.id}">Type</span></td>
<td><span th:text="${Reports.solved}" th:value="${Reports.id}">Solved</span></td>
如果要在每行中添加按钮,只需将按钮代码放在每个td中,并提供类似URL的网址-
<button class="btn btn-secondary href="/someurl/"+${Reports.id}>Solved</button>
答案 1 :(得分:0)
如果通过POST发送,则需要创建一个新对象并将这两个值添加到新对象中。
创建一个将th:action设置为POST端点的HTML表单,并添加一个接受两个值的th:object。然后使用两个隐藏的输入字段,并使用th:value将其值设置为要发送的值。
希望这有意义,如果以后没有其他人回答/以后需要更多帮助,我可以稍后添加一个编码示例。目前仅在移动设备上。
答案 2 :(得分:0)
您可以使用Tabledit.js。
<script th:src="@{[javascript_folder_path]/jquery.tabledit.js}"></script>
<script type="text/javascript">
$('#tableEdit').Tabledit({
url: "your_controller",
//saveButton: false,
columns: {
//identifier is used as a unique id for passing your id for db operation
identifier: [0, 'id'],
//Only include those fields that you want to make editable here.
editable: [[0, 'id'], [1, 'description'], [2, 'entity'], [3, 'long'], [4, 'lat'], [5, 'type'], [6, 'solved']]
}
});
$('#tableEdit').editableTableWidget().numericInputExample().find('td:first').focus();
$('#textAreaEditor').editableTableWidget({editor: $('<textarea>')});
window.prettyPrint && prettyPrint();
</script>