2017-02-21 105 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

感谢的人!它工作 –