我怎样才能从 thymeleaf 为 bootstrap aria-controls 标签增量增加

How can I make increment for boostrap area-controls tag increment from thymeleaf

我需要在 aria-controls bootstrap 选项卡中增加我的列表计数。 我的代码如下:

<th:block th:each="stateTitles, statesStatus: ${states}">
    <a data-toggle="collapse" id="stateCollapsed" class="collapsed" data-parent="#accordion" th:href="'#collapse' + ${statesStatus.index + 1}" 
        aria-expanded="true" aria-controls="'collapse' + ${statesStatus.index + 1}">
        <span id="state" th:text="${stateTitles}" /> 
        <span class="glyphicon glyphicon-menu-down"></span>
        <span class="glyphicon glyphicon-menu-up"></span>
    </a>
</th:block>

增量不适用于区域控制标签。 提前致谢。

您需要使用 th:attr 才能使用 Thymeleaf 注入值,请查看文档 here

所以把代码改成:

<a data-toggle="collapse" id="stateCollapsed" class="collapsed" data-parent="#accordion" th:href="'#collapse' + ${statesStatus.index + 1}" 
        aria-expanded="true" th:attr="aria-controls='collapse' + ${statesStatus.index + 1}">