【问题标题】:Bootstrap panels within Thymeleaf loop - same id and hrefThymeleaf 循环中的引导面板 - 相同的 id 和 href
【发布时间】:2017-07-15 05:34:30
【问题描述】:

我正在尝试在 Thymeleaf 循环中生成引导折叠面板,如下所示:

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

【问题讨论】:

    标签: javascript jquery twitter-bootstrap frontend thymeleaf


    【解决方案1】:

    您可以使用 status 变量 (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">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-11
      • 2019-03-27
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      • 2017-05-12
      • 1970-01-01
      相关资源
      最近更新 更多