2017-01-29 3 views
0

後、私はテーブルを持っている:私はアンカーをクリックするとリセットモーダル内容オープン

<table class="table table-striped"> 
    <thead> 
    <tr> 
     <th>Naam</th> 
     <th>E-mail</th> 
     <th>Verwijderen</th> 
    </tr> 
    </thead> 
    <tbody> 
    @foreach($customers as $customer) 
     <tr> 
      <td><a href="{{ route('admin_customers_single', $customer->id) }}">{{ $customer->name }}</a></td> 
      <td>{{ $customer->email }}</td> 
      <td><a href="{{ route('admin_customers_delete', $customer->id) }}"><span class="glyphicon glyphicon-trash"></span></a></td> 
     </tr> 
    @endforeach 
    </tbody> 
</table> 

、モデルがデータを開きます。

$(document).on('click', 'a', function (event) { 
     event.preventDefault(); 

     var url = $(this).attr('href'); 

     $.ajax({ 
      dataType: 'json', 
      type: 'GET', 
      url: url, 
      success: function (data) { 
       console.log(data); 

       $('#nameInput').val(data.name); 
       $('#genderInput').val(data.gender); 
       $('#addressInput').val(data.address); 
       $('#zipCodeInput').val(data.zip_code); 
       $('#cityInput').val(data.city); 
       $('#countryInput').val(data.country_id); 
       $('#languageInput').val(data.language); 
       $('#emailInput').val(data.input); 

       $('#myModal').modal('show'); 
      } 
     }); 
    }); 

データが表示されるので機能します。

<a class="btn btn-primary" href="#" data-toggle="modal" data-target="#myModal" role="button">@lang('admin.customers_new')</a> 

このアンカーをクリックすると、データが残って..です は、どのように私は、そのデフォルトのコンテンツへのモーダルをリセットするのですか?

+0

私の答えはあなたを助けていますか? –

答えて

0

hidden.bs.modalイベントを使用してください。

このイベント

はモーダルが ユーザーから隠されて終了したときに発生する(CSSの遷移が完了するのを待ちます)。

$('#myModal').on('hidden.bs.modal', function (e) { 
    // Reset the fields values here. 
}) 

Source

+0

ありがとう、それは働いた! – yooouuri