2017-04-01 51 views
1

私はthymeleafに新規です。trのIDを作成し、動的行を取得しようとしています。Thymeleaf-テーブル行の動的IDを作成

テーブルの行は正常に取得されましたが、thymeleafの各行のidを作成するのは難しいです。

<table class="table table-hover" id="table"> 
       <thead style="background-color:#CCE5FF"> 
       <tr> 
        <th>ID</th>      
        <th>Code</th>     
        <th>Created Date</th>    
        <th></th> 
       </tr> 
       </thead> 
       <tbody> 
       <tr th:each="emp,iterStat : ${empList}"> 
        <td th:text="${emp.id}">ID</td> 
        <td th:text="${emp.mdrcode}">Code</td> 
        <td th:text="${emp.createDate}">Created Date</td>      
        <td><a id="editview" class="btn btn-sm btn-default" th:href="@{/}"><i class="fa fa-edit"></i> View</a></td> 
       </tr> 
       </tbody> 
       </table> 

答えて

1

これにはth:idを使用できます。

<!-- this would assign the emp.id to the id attribute of the tr. 
<tr th:id="${emp.id}" th:each="emp,iterStat : ${empList}"> 
    <td th:text="${emp.id}">ID</td> 
    <td th:text="${emp.mdrcode}">Code</td> 
    <td th:text="${emp.createDate}">Created Date</td> 
    <td><a id="editview" class="btn btn-sm btn-default" th:href="@{/}"><i class="fa fa-edit"></i> View</a></td> 
</tr> 

また、IDにいくつかのテキストを追加することができます。

<!-- this would assign someText + emp.id to the id attribute of the tr. 
<tr th:id="'someText__${emp.id}__'" th:each="emp,iterStat : ${empList}"> 
    <td th:text="${emp.id}">ID</td> 
    <td th:text="${emp.mdrcode}">Code</td> 
    <td th:text="${emp.createDate}">Created Date</td> 
    <td><a id="editview" class="btn btn-sm btn-default" th:href="@{/}"><i class="fa fa-edit"></i> View</a></td> 
</tr> 
+0

それがうまく働いていただきありがとうございます。しかし、これを表示する可能性は、jqueryを使用して警告ボックスに表示されますか? – Durga

+0

これらの 'tr'タグにクラスを追加してクリックリスナーを追加し、' .attr( 'id') ' –

関連する問題