簡體   English   中英

如何使用百里香葉值傳遞到引導數據?

[英]how to pass a value using thymeleaf to data of bootstrap?

我想使用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}“”

  1. th:text的目的是修改元素(在本例中為button元素)的主體文本。 您正在嘗試設置屬性值。
  2. 如果要讓百里香葉修改數據屬性(如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}"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM