【问题标题】:Get data from thymeleaf to a modal bootstrap, jquery从 thymeleaf 获取数据到模态引导程序 jquery
【发布时间】:2021-11-24 17:12:13
【问题描述】:

我正在尝试为模态视图获取“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');

【问题讨论】:

标签: javascript jquery bootstrap-4 modal-dialog thymeleaf


【解决方案1】:

最后,经过大量的搜索和尝试,我找到了解决方案,希望它对正在苦苦挣扎的人有所帮助,诀窍是将模态放在 table 或 div 的同一循环中,并创建动态“id”带有 thymeleaf 的属性句,就像在这个 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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-19
    • 2021-05-06
    • 2015-02-28
    • 2021-01-22
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    相关资源
    最近更新 更多