简体   繁体   中英

Get data from thymeleaf to a modal bootstrap, jquery

I am trying to get an "id" to a modal view, this is in order to updated a "onclick" element, but I don't find a way:(, any idea how this could be done for boostrap 5, ¿or other way I could do it? Thanks !

  <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');

Finally, thanks to lot of searching and trying, I found the solution, hope it helps with who is struggling, the trick is to put the modal inside the same loop of the table or div, and creating and dynamic "id" with the attribute sentence of thymeleaf, like is explained in this page for an older version:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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