drr7731 2019-05-05 09:09
浏览 77

Bootstrap模式仅从动态表中删除第一行

I have a problem with passing the dynamic variable to the modal section. Every time I take the first row from the table and as a result bootstrap's modal isn't working properly. I use Laravel freamework.

How can I pass a dynamic variable to a section? Can somebody help me?

Here's my code:

showCustomer.blade.php

<div class="row">
<div class="col-12">
    <table id="myTable" class="table table-hover display" cellspacing="0" width="100%">
        <thead class="thead-light">
            <tr>
                <th class="th-sm">ID</th>
                <th class="th-sm">Name</th>
                <th class="th-sm">Surname</th>
                @if($perm === true)
                <th class="no-sort"></th>
                @endif
            </tr>
        </thead>
        <tbody>
            @foreach($customers as $customer)
            <tr>
                <td>{{$customer->id}}</td>
                <td class="font-weight-bold">{{$customer->name}}</td>
                <td>{{$customer->surname}}</td>
                @if($perm === true)
                <td class="text-right">
                    <div class="btn-group" role="group">
                        <!-- Button trigger delete modal -->
                        <button type="button" class="btn btn-danger" data-toggle="modal"
                            data-target="#deleteModal{{$customer->id}}"><i class="far fa-trash-alt"></i></button>

                        <!-- Delete button -->
                        @section('deleteModalAction')
                        <a href="{{ route('backstage.removeCustomer',$customer->id) }}" class="btn btn-primary"
                            role="button">Yes</a>
                        @endsection('deleteModalAction')

                        @include('components.deleteModal')

                        <!-- Edit button -->
                        <a href="{{ route('backstage.showCustomerForm',$customer->id) }}">
                            <button type="button" class="btn btn-default">
                                <i class="far fa-edit"></i></button> </a>
                    </div>
                </td>
                @endif
            </tr>
            @endforeach
        </tbody>
    </table>
</div>

removeModal.blade.php

<div class="modal fade" id="deleteModal{{$customer->id}}" tabindex="-1" role="dialog" aria-labelledby="deleteModal"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <h5 class="modal-title" id="deleteModal">Confirm</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
            <p class="text-center">Are you sure?</p>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
            @yield('deleteModalAction')
        </div>
    </div>
</div>

Every single time, the section 'deleteModalSection'has the same variable (first id for the dynamic table)...

I had tried a lot of ways, but to no avail.

Generally, bootstrap modal is to be universal for the rest of views.

Thank you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!