2016-02-09 218 views
0

我嘗試從Thymeleaf和Twitter Bootstrap的元素列表創建表。 表格行應該每個都可以通過點擊來放大。帶Bootstrap的Thymeleaf:摺疊/手風琴表

我試圖用標準引導機制與'data-toogle'和'accordion'做到這一點。

問題是我不能讓Thymeleaf從列表中打印兩行的每個條目。我可以歸檔的最好的是以下幾個問題,即開放主體位於原始表格下。

<table class="table table-striped table-hover"> 
     <thead> 
       <th>Name</th> 
       <th>Value</th> 
     </thead> 
     <tbody> 
      <tr th:each="result: ${results}" th:attr="data-target='#accordion_'+${result.name}" data-toggle="collapse" class="accordion-toggle"> 
        <td th:text="${result.name}"></td> 
        <td th:text="${result.value}"></td> 
      </tr> 

      <tr th:each="result: ${results}"> 
        <td colspan="6" class="hiddenRow"> 
         <div class="accordion-body collapse" th:id="'#accordion_'+${result.name}">there is nothing to see here (yet) 
         </div> 
        </td> 
      </tr> 
     </tbody> 
    </table> 

所以有不同的問題/答案在這裏:

  1. 是否有Thymeleaf一個方法來打印每個列表項的兩行?
  2. 是否有一個更好的機制,可以與Thymeleaf進行可摺疊列表項目?
+0

這可能幫助他人打印Thymeleaf兩行:http://damienfremont.com/2014/12/19/how -to-expandcollapse-table-rows-with-bootstrap/ – mnzl

回答

1

您可以通過使用th:block標籤這樣的(未測試)

<th:block th:each="result: ${results}"> 
    <tr th:attr="data-target='#accordion_'+${result.name}" data-toggle="collapse" class="accordion-toggle"> 
     <td th:text="${result.name}"></td> 
     <td th:text="${result.value}"></td> 
    </tr> 
    <tr> 
     <td colspan="6" class="hiddenRow"> 
      <div class="accordion-body collapse" th:id="'#accordion_'+${result.name}">there is nothing to see here (yet)</div> 
     </td> 
    </tr> 
</th:block> 
+0

謝謝,如果id與文件名相同,請記住從名稱中刪除點。 Id與。在它不好。 – mnzl