2017-06-26 10 views
0

Bootstrapからデータに値を渡すためにThymeleafを使用したいと思います。thymeleafを使ってブートストラップのデータに値を渡す方法は?

私はそれを行う方法がわかりません。手伝って頂けますか?

<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> 

答えて

0

次の行は意味をなさない: データID = "番目:テキスト=" $ {car.id} ""

  1. 番目の目的:テキストは本体を修正することです要素のテキスト(この場合はボタン要素)。属性値を設定しようとしています。
  2. あなたはthymeleafデータ-IDなどのデータ属性を変更したい場合、あなたは番目する必要があります。次のようにattrの代わりに

その行が書かれるべきである。

data-id="" th:attr="data-id=${car.id}" 

あなたはデータが必要な場合-idは "example-id"のようなデフォルト値を持つために、これをしてください:

data-id="example-id" th:attr="data-id=${car.id}" 
+0

ありがとうございました。 同じボタンに別の属性を追加したいのですが? data-id = "" th:attr = "data-id = $ {car.id}" 例: データ名= "":attr = "データ名= $ {car.name}" 最初の属性がボタンに割り当てられているため、他のデータを追加すると1つの属性でうまく動作するため、 私は助けてくれることを願っています – Reiko

+0

これを解決するにはth:attr = "data -id = $ {car.id}、データ名= $ {car.name} " – Reiko

関連する問題