循环中的Thymeleaf模态数据目标和id更新

问题描述 投票:0回答:1

我正在构建一个Thymeleaf + SpringBoot应用程序,我有一个Thymeleaf foreach循环的时刻我在一个div内有一个模态 - 它重复几次,我想更新一个模态的索引和显示它的按钮,以便我的模态将通过特定按钮显示。我有更新索引的问题,因为当我这样做时,我的按钮停止工作,没有显示模态...

我检查了:

a)How can I do data-target="#userId" in thymeleaf

b)using data-* attribute with thymeleaf

但它仍然不起作用......

这是代码的一部分:循环:

<div th:each="myth : ${allMyths}">

这里是按钮(注释代码也不起作用......):

<button type="button" class="button" style="float: right; margin-right: 2%" data-toggle="modal"
                        data-th-target="'#'+${myth.getId()}">More...
                        <!--th:attr="data-target='#'+${myth.getId()}">More...-->
                </button>

这里是模态的顶部:

<div data-th-id="${myth.getId()}" class="modal fade" role="dialog">

这里也是:id不起作用...你知道为什么按钮和模态没有通过ID找到对方吗?

提前感谢您的回答/建议!

彼得·

spring-boot bootstrap-modal thymeleaf
1个回答
0
投票

按钮:

<button type="button" class="button" style="float: right; margin-right: 2%" data-toggle="modal" th:attr="data-target='#'+${myth.getId()}">More...</button>

莫代尔之巅:

<div th:attr="id=${myth.getId()}" class="modal fade" role="dialog">
© www.soinside.com 2019 - 2024. All rights reserved.