动态复选框 + Table 使用 Blade 框架和 Laravel
Dinamic Check Box + Table With Blade Famework and Laravel
我需要在 table 行中组织我的复选框字段。
我想要 blade 每 10 个项目打破 table 行。
这是我的代码:
<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>
您不断地打开一个新的行标签,但每 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>
怎么样:
<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>
我需要在 table 行中组织我的复选框字段。
我想要 blade 每 10 个项目打破 table 行。
这是我的代码:
<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>
您不断地打开一个新的行标签,但每 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>
怎么样:
<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>