将数据从 thymeleaf 获取到模态 bootstrap、jquery

Get data from thymeleaf to a modal bootstrap, jquery

我正在尝试获取模态视图的“id”,这是为了更新“onclick”元素,但我找不到方法:(,不知道如何做到这一点boostrap 5,或其他我可以做到的方式?谢谢!

  <tr th:each="user: ${users}">
    <a data-bs-toggle="modal" th:title="active" th:id="${user.id}"   th:attr="data-target='#modal-warning'+${user.id }" data-bs-target="#modal-view">inactivate</a>
<div th:fragment="modal" class="modal fade modal-warning" th:id="modal-warning+${clinicalRepresentative.id }" tabindex="-1" role="dialog" aria-labelledby="label-modal-1" > 
<div class="modal-dialog">
    <div class="modal-footer">

<input  th:onclick="'location.href=\'/inactivate/' + (id=${clinicalRepresentative.id}) +'\''"            /> 
<script>
    $(document).ready(function() {
        var id;
        $('[title="active"]').click(function() {
            id = $(this).attr('id');

最后,由于大量的搜索和尝试,我找到了解决方案,希望它能帮助那些正在挣扎的人,诀窍是将模态放在 table 或 [=14 的同一个循环中=],并使用 thymeleaf 的属性语句创建和动态“id”,如此 page 中对旧版本的解释:

    <tr th:each="user: ${users}">
        <td ><a data-bs-toggle="modal" data-row="${user}"
                th:attr="data-bs-target='#modal-warning'+${user.id }">Inactivate</a> 
    
    <!--  MODAL -->
  <div th:fragment="modal" class="modal fade" th:id="modal-warning+${user.id }" tabindex="-1"