我想使用 Thymeleaf 将值传递给 Bootstrap 中的数据。
我不知道该怎么做。你能帮我吗?
<tr th:each="car : ${lCars}" class="succes">
<td th:text="${car.id}"></td>
<td th:text="${car.name}"></td>
<td align="center">
<button type="button" class="btn btn-primary"
data-toggle="modal" data-target="#editar" title="Edit"
data-id= "th:text="${car.id}"" <!-- I want to pass this value on to the data, but this way doesn't work -->
data-name="myCar" <!-- If I send a simple word, works well -->
<span class="glyphicon glyphicon-pencil"></span> Edit
</button>
</td>
</tr>
最佳答案
下面这行没有任何意义: data-id="th:text="${car.id}""
- th:text 的目的是修改元素(在本例中为按钮元素)的正文文本。您正在尝试设置属性值。
- 如果您希望 thymeleaf 修改 data-id 等数据属性,则需要改为 th:attr
该行应写成如下:
data-id="" th:attr="data-id=${car.id}"
如果您希望 data-id 有一些默认值,例如“example-id”,请执行以下操作:
data-id="example-id" th:attr="data-id=${car.id}"
关于java - 如何使用 thymeleaf 将值传递给 bootstrap 的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44765632/