2017-07-15 47 views
0

我試圖內Thymeleaf loop產生引導摺疊面板,這樣的:引導面板 - 相同的ID和HREF

<table> 
    <tr th:each="p, iterStat : ${completedList}"> 
     <td style="padding: 0 15px 0 15px;"> 
      <div class="panel panel-success"> 
       <div class="panel-heading"> 
        <h4 class="panel-title"> 
         <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" th:text="${p.key}">p.k</a><span style="float: right;" class="glyphicon glyphicon-ok"></span> 
        </h4> 
       </div> 
       <div th:id="collapseOne" class="panel-collapse collapse in"> 
        <div class="panel-body"> 
         <span th:text="${p.value}"></span> 
        </div> 
       </div> 
      </div> 
     </td> 
    </tr> 
</table> 

但我對循環的每個元素相同idhref等等面板不起作用。

我可以做一些動態更改idhref

回答

0

可以使用狀態變量iterStat)創建一個獨特的ID爲每一行:

<a data-toggle="collapse" data-parent="#accordion" th:href="'#collapse' + ${iterStat.index}" th:text="${p.key}"> 

<div th:id="'collapse' + ${iterStat.index}" class="panel-collapse collapse in">