2017-02-21 90 views
0

我需要組織表格中的複選框字段。Dinamic複選框+刀片Famework和Laravel表

我希望每次10項的刀片破損的錶行。

這裏是我的代碼:

<table> 

    <div class="btn-group" data-toggle="buttons"> 
    {{$i = 0}} 

    @foreach($sintese as $s) 
     <tr> 
      <td> 
       <label class="btn btn-primary"> 
        <input type="checkbox" autocomplete="off" name="chksintese" id="{{$s->cod_sintese_conversa}}"> 
        <span class="glyphicon glyphicon-ok"></span> 
        {{$s->descricao}} 
       </label> 
      </td> 

      @if ($i > 10) 
       {{'</tr>'}} 
       {{$i = 0}} 
      @else 
       {{$i++}} 
      @endif 

     @endforeach 
    </div> 

</table> 

And Here is My Result:

回答

1

什麼:

<table> 
    <div class="btn-group" data-toggle="buttons"> 
     <tr> 
      @foreach($sintese as $s) 
       <td> 
        <label class="btn btn-primary"> 
         <input type="checkbox" autocomplete="off" name="chksintese" id="{{$s->cod_sintese_conversa}}"> 
         <span class="glyphicon glyphicon-ok"></span> 
         {{$s->descricao}} 
        </label> 
       </td> 

       @if ($loop->iteration % 10 == 0 && !$loop->last) 
        </tr><tr> 
       @endif 
      @endforeach 
     </tr> 
    </div> 
</table> 
+0

有人知道如何在Vue.js中做到這一點? –

0

你不斷地打開一個新的行代碼,而只是將其關閉每10你也呼應了櫃檯,這是不需要。相反,在循環之前打開它,然後每10次重置一次。不要重置$ i,而是根據餘數運算符對其進行檢查,並確保不會創建空行。

<tr> 
@foreach($sintese as $s) 
     <td> 
      <label class="btn btn-primary"> 
       <input type="checkbox" autocomplete="off" name="chksintese" id="{{$s->cod_sintese_conversa}}"> 
       <span class="glyphicon glyphicon-ok"></span> 
       {{$s->descricao}} 
      </label> 
     </td> 

     @if ($i % 10 == 0 && $i < count($sintese)) 
      <tr/><tr> 
     @endif 
    <?php $i++ ?> 

    @endforeach 
    </tr> 
+0

感謝的人!它工作 –