【发布时间】:2019-05-17 13:28:02
【问题描述】:
我有这个:
@GetMapping("/records")
public String getRecords(Model model) {
model.addAttribute("tallies", getAllTallies(null));
model.addAttribute("categories", getCategories());
return "records";
}
getCategories() 只返回一个Categorys 的列表,getAllTallies 只返回一个所有Tallys 的列表。
如果请求的参数category 为空,那么它将返回所有计数,无论类别。但是如果它不为空,那么它将只从指定的category返回所有tallies。
这是getAllTallies:
@GetMapping("/tallies")
@ResponseBody
public List<Tally> getAllTallies(@RequestParam(required = false) String category)
然后在我的records.html:
<body>
<div>
<select class="form-control" >
<option value="0">Select Category</option>
<option th:each="category : ${categories}" th:value="${category.id}" th:text="${category.category}"></option>
</select>
</div>
<table cellpadding="10" border="1px">
<thead>
<tr>
<th> Nominee </th>
<th> Category </th>
<th> Tally </th>
</tr>
</thead>
<tbody>
<tr th:if="${tallies.empty}">
<td colspan="3"> No Books Available </td>
</tr>
<tr th:each="tally : ${tallies}">
<td><span th:text="${tally.nominee}"> Nominee </span></td>
<td><span th:text="${tally.category}"> Category </span></td>
<td><span th:text="${tally.count}"> Tally </span></td>
</tr>
</tbody>
</table>
</body>
我想要做的是,每当我从下拉列表(类别)中选择一个新值时,表格也会根据类别而变化。 我在想这是否可能没有 jquery 或 js,只有 html。但是我很难弄清楚如何通过下拉列表动态更新表格。
【问题讨论】:
-
您必须在每次下拉更改 (ajax) 时提出请求,
标签: javascript java spring spring-boot thymeleaf