2016-06-29 7 views
0

私は、都市と教育機関の2つのフィールドのドロップダウンを行う必要があるフォームで作業する必要があります。ユーザーが都市を選択すると、教育機関のオプションが更新されます。つまり、その都市の施設が表示されます。私はバックエンドでLaravelに取り組んでいます。私は物事がどのように機能するか少し考えていますが、私は深い理解を得る必要があります。ご案内ください。次の手順のような機能の外観を実装するとき、私は通常行うドロップダウンオプションを動的に更新する

+0

あなたはそのためにAJAXを使う必要があります。それについていくつかの研究を行ってください。 – linuxartisan

答えて

0

もの:

。 HTMLの入力フィールドに

<select class="action-select-city"></select>

<select class="select-education"></select>

を作成します。お使いのjQueryの変更イベント

$('.action-select-city').change(function (e) { 

    var val = $(this).val(); 

    $education = $('.select-education'); 

    $.ajax({ 
     // Your settings etc 
     success: function (data) 
     { 
      // Clear existing options 
      $education.html(''); 

      // Loop data and insert new options 
      for(var i = 0; i < data.length; i++) 
      { 
       $education.append('<option ... option>'); 
      } 
     } 
    }); 

}); 

を作成します。ルート

Route::post('/something', '[email protected]')

を作成します。コントローラーとメソッドを作成する

class SomeController extends Controller 
{ 

    public function someMethod(Request $request) 
    { 

     // Always good to validate 
     $this->validate($request, ['some rules']); 

     // Get all educations in city 
     $educations = ..... 

     return response()->json($educations); 

    } 

} 

このソリューションは明らかにテストされておらず、特定のものの名前付けが優れている可能性があります。私はこの答えが役に立つと願っています:)

関連する問題