2016-05-23 5 views
1

ユーザーがドロップダウンから選択したオプション要素に関連するデータを表示するテーブルをレンダリングしようとしています。基本的にはテーブルは選択に基づいて情報を表示することしか想定されていませんが、私は(エントリーレベルのプログラマーである)私はこれをどうやって行うのか分かりません。何か案は?ここに私のコードだ:Laravelのオプションタグに基づいてテーブルをレンダリングする

<style> 
    .tableContainer { 
     display: none; 
    } 
</style> 

<script type="text/javascript"> 
    $(document).ready(function() { 

     $(".js-example-basic-single").select2(); 

     $("#renderBtn").on("click", function(){ 
     $(".tableContainer").css("display", "block"); 
     }); 
    }); 
</script> 

       <select class="js-example-basic-single"> 
        <optgroup label="HTML"> 
         @foreach ($assetList as $asset) 
          @if($asset->asset_type_id == 1) 
           <option data-id="{{$asset->asset_id}}" value="{{$asset->title}}">{{$asset->title}}</option> 
          @endif 
         @endforeach 
        </optgroup> 
        <optgroup label="PDF"> 
         @foreach ($assetList as $asset) 
          @if($asset->asset_type_id == 2) 
           <option data-id="{{$asset->asset_id}}" value="{{$asset->title}}">{{$asset->title}}</option> 
          @endif 
         @endforeach 
        </optgroup> 
        <optgroup label="VIDEO"> 
         @foreach ($assetList as $asset) 
          @if($asset->asset_type_id == 3) 
           <option data-id="{{$asset->asset_id}}" value="{{$asset->title}}">{{$asset->title}}</option> 
          @endif 
         @endforeach 
        </optgroup> 
       </select> 
       <button id="renderBtn" class="btn">Render Table</button> 
       <div id="tableContainer" class="tableContainer"> 
        <table id="userAssetTable" class="table"> 
         <thead> 
          <tr> 
           <td>Asset ID</td> 
           <td>Asset</td> 
           <td>Action Type</td> 
           <td>Message</td> 
           <td>Created At</td> 
           <td>Updated At</td> 
          </tr> 
         </thead> 
         @foreach ($actionList as $action) 
          <tr> 
           <td>{{$action->asset_id}}</td> 
           <td> 
            @foreach ($assetList as $asset) 
             @if($action->asset_id == $asset->asset_id) 
              {{$asset->title}} 
             @endif 
            @endforeach 
           </td> 
           <td>{{$action->action_type_id}}</td> 
           <td>{{$action->message}}</td> 
           <td>{{$action->created_at}}</td> 
           <td>{{$action->updated_at}}</td> 
          </tr> 
         @endforeach 
        </table> 
       </div> 
+0

Ajaxでこれを実行しようとしていますか?そのデータは選択後にサーバーから送信されますか? – Digitlimit

+0

はい。私は、データがどこから来ているのかを示すサーバを稼働させています。 –

答えて

0

はあなただけで、その後のJavascriptを通してあなたの方法を作業、オプション要素にデータ-ID属性を使用してみましたか?例:

<option data-id="exampleID">Option1</option> 
<script> 
*Use a loop to filter through data here* 
</script> 
関連する問題