如何通过ID显示模态数据

时间:2019-08-13 04:31:04

标签: laravel

我有表数据,它显示数据库中的数据。 我想使用Action显示数据,并且它将显示Modal和数据。

我的观点是这样的:

<div class="table-responsive">
                  <table class="table table-striped jambo_table bulk_action" id="table2">
                    <thead>
                      <tr class="headings">
                        <th class="column-title" style="display: table-cell;">No </th>
                        <th class="column-title" style="display: table-cell;">Nama Pegawai </th>
                        <th class="column-title" style="display: table-cell;">Lihat Data Keluarga </th>
                      </tr>
                    </thead>

                    <tbody>
                         @php
                        $no=0;
                       @endphp
                       @foreach ($keluarga as $i)
                      <tr class="even pointer">
                        <td class="a-center ">{{ ++$no }}</td>
                        <td class=" ">{{ $i->users->nama}} </td>
                      <td class=" "><a href="/project/d_keluarga/show-keluarga/{{$i->id}}"><button type="button" class="btn btn-danger" data-toggle="modal" data-target=".bs-example-modal-lg"> Show Data</button> // to showing data By Id on table

                        </td>
                      </tr>
                      @endforeach 
                      <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true">
                          <div class="modal-dialog modal-lg">
                            <div class="modal-content">

                              <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span>
                                </button>
                               <h4 class="modal-title" id="myModalLabel">Data Keluarga</h4>
                              </div>
                              <div class="modal-body">
                                <h4></h4>
                                //here to paste data
                              </div>
                              <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <button type="button" class="btn btn-primary">Save changes</button>
                              </div>

                            </div>
                          </div>
                        </div>



                    </tbody>
                  </table>
                </div>

我的控制器:

public function keluarga()
{
    $keluarga = Data_keluarga::with('users')->get();
    return view('admin.keluarga',['keluarga' => $keluarga ]);
}

i通常像$ i-> name及其它在另一页中一样解析它。不在Modal中。

但是,如何通过id显示模式数据?

1 个答案:

答案 0 :(得分:0)

确切的问题是an answer

  1. data-title="{{ $i->users->nama }}"添加到您的按钮中。
<button type="button" class="btn btn-danger" data-toggle="modal" data-target=".bs-example-modal-lg" data-title="{{ $i->users->nama }}"> Show Data</button>
  1. 添加此jQuery代码段。
$('.bs-example-modal-lg').on('show.bs.modal', function (event) {
      var button = $(event.relatedTarget)
      var title = button.data('title')
      // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
      // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
      var modal = $(this)
      modal.find('.modal-title').text(title)
})