繁体   English   中英

从 thymeleaf 获取数据到模态引导程序 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 或 div 的同一个循环中,并使用属性创建和动态“id” thymeleaf 的句子,就像在这个页面中解释的旧版本一样:

    <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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM