【发布时间】:2021-01-21 08:51:29
【问题描述】:
我在 laravel 刀片文件中有这个表。
@foreach($items as $item)
<table class="pack-table">
<tr>
<th width="30%">Color</th>
<th width="10%">Pack</th>
<th width="60%">Total Units</th>
</tr>
<tr>
<td>
@foreach($item['grid'] as $color => $sizes)
{{$color}}<br><br>
@endforeach
</td>
<td>
@foreach ($item['grid'] as $color => $sizes)
@foreach ($sizes as $size)
{{ $size['description'] }}<br><br>
@endforeach
@endforeach
</td>
<td>
@foreach ($item['grid'] as $color => $sizes)
@foreach ($sizes as $size)
{{ $size['total'] }}<br><br>
@endforeach
@endforeach
</td>
</tr>
</table>
@endforeach
此代码在图片中打印如下表格。
这只是打印每个数据。但我希望打印如下: 例如颜色,VELBL 的尺寸为 MEDIUM、X LARGE、LARGE、X SMALL 和 SMALL,所有这些包装尺寸的总单位为 0 .
所以我需要先打印所有这些记录,然后再打印下一种颜色BLUAS,它是包装尺寸,以及每种颜色的总和。
如何修改我的代码以根据需要打印?
<table class="pack-table">
<tr>
<th width="30%">Color</th>
<th width="10%">Pack</th>
<th width="60%">Total Units</th>
</tr>
@foreach($item['grid'] as $color => $sizes)
<tr>
<td colspan="3" align="left">{{ $color }}</td>
</tr>
@foreach ($sizes as $size)
<tr>
<td>{{ $size['description'] }}</td>
<td>{{ $size['total'] }}</td>
</tr>
@endforeach
@endforeach
</table>
【问题讨论】:
-
你可以用 div 做得更好。如果你想用
来做,你必须在你的
中做 sub
来分组数据
你能给我一个关于子表的例子吗?
标签: laravel foreach html-table laravel-blade