Table 在视图上输出额外的 <td>
Table outputting extra <td>'s on View
我试图在我的视图中输出一个多维数组,但在 table 上得到了一些古怪的输出。这是我所拥有的屏幕截图:
这是我使用的代码:
</tr>
@endforeach
</tbody>
</table>
我认为这与我的 if else 语句有关,但现在已经在这个问题上停留了一段时间。任何帮助将非常感激!谢谢
编辑:根据要求,这是我的数据结构,它是 var_dump:
如果没有你的数据结构就很难说,但我想问题出在你的数据结构和嵌套的 foreach 上。
当您检查 $status 时,您将遍历数组。第一次循环遍历数组$status == 1
,但是每次查看状态都在写入一个td
@foreach ($count as $status => $c)
@if($status == 2)
<td><a href="#">{{$c}}</a></td>
@else
<td> </td>
@endif
...
@endforeach
所以在第一遍假设 $status = 1
;你会得到
<td> </td>
<td><a href="#">{{$c}}</a></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
在第二遍中,假设 $status = 2
你将得到:
<td><a href="#">{{$c}}</a></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
但你还是第一人称。
您可能会考虑将数据结构更改为类似这样的内容。这是伪代码,请根据需要进行修改。
$person = [
$totals => [
$qualifiedProspectCount => 2,
$unqualifiedProspectCount => 2,
$contactedCount => 2,
$qualifiedProspectCount => 2,
$convertedToAccountCount => 2,
$pendingIntegrationCount => 2,
$revenueGeneratingCountCount => 2
]
];
然后像这样只浏览一次你的数据。我将 提取为部分内容,但您可以继续内联执行。
page.blade.php
<table class="table tablesorter" id="tblAffs">
<thead>
<tr class="tblhead">
<th>AM</th>
<th>Qualified Prospect</th>
<th>Unqualified Prospect</th>
<th>Contacted</th>
<th>Converted To Account</th>
<th>Pending Integration</th>
<th>Revenue Generating</th>
</tr>
</thead>
<tbody>
$totalCount should be a collection of $person
@foreach ($totalCount as $name => $totals)
<tr>
<td>
{{$name}}
<br>
<a href="#">Closed</a>
</td>
@include('partial.item', 'count' => $totals->qualifiedProspectCount)
@include('partial.item', 'count' => $totals->unqualifiedProspectCount)
@include('partial.item', 'count' => $totals->contactedCount)
@include('partial.item', 'count' => $totals->convertedToAccountCount)
@include('partial.item', 'count' => $totals->pendingIntegrationCount)
@include('partial.item', 'count' => $totals->revenueGeneratingCountCount)
</tr>
@endforeach
</tbody>
partial/item.blade.php
@if($count > 0)
<td><a href="#">{{{$count}}}</a></td>
@else
<td> </td>
@endif
编辑
所以这会让你以后陷入各种麻烦,但现在就开始吧。
@foreach ($totalCount as $name => $count)
<tr>
<td>
{{$name}}
<br>
<a href="#">Closed</a>
</td>
@if(isset($count[2]))
<td><a href="#">{{ $count[2] }}</a></td>
@else
<td> </td>
@endif
@if(isset($count[1]))
<td><a href="#">{{ $count[1] }}</a></td>
@else
<td> </td>
@endif
// and so on ...
</tr>
@endforeach
我建议您检查一下 Laravel's Documentation,有很多方法可以完成您正在尝试做的事情,这些方法比您正在做的事情要容易得多。虽然感觉快了点。不是。
我试图在我的视图中输出一个多维数组,但在 table 上得到了一些古怪的输出。这是我所拥有的屏幕截图:
这是我使用的代码:
</tr>
@endforeach
</tbody>
</table>
我认为这与我的 if else 语句有关,但现在已经在这个问题上停留了一段时间。任何帮助将非常感激!谢谢
编辑:根据要求,这是我的数据结构,它是 var_dump:
如果没有你的数据结构就很难说,但我想问题出在你的数据结构和嵌套的 foreach 上。
当您检查 $status 时,您将遍历数组。第一次循环遍历数组$status == 1
,但是每次查看状态都在写入一个td
@foreach ($count as $status => $c)
@if($status == 2)
<td><a href="#">{{$c}}</a></td>
@else
<td> </td>
@endif
...
@endforeach
所以在第一遍假设 $status = 1
;你会得到
<td> </td>
<td><a href="#">{{$c}}</a></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
在第二遍中,假设 $status = 2
你将得到:
<td><a href="#">{{$c}}</a></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
但你还是第一人称。
您可能会考虑将数据结构更改为类似这样的内容。这是伪代码,请根据需要进行修改。
$person = [
$totals => [
$qualifiedProspectCount => 2,
$unqualifiedProspectCount => 2,
$contactedCount => 2,
$qualifiedProspectCount => 2,
$convertedToAccountCount => 2,
$pendingIntegrationCount => 2,
$revenueGeneratingCountCount => 2
]
];
然后像这样只浏览一次你的数据。我将 提取为部分内容,但您可以继续内联执行。
page.blade.php
<table class="table tablesorter" id="tblAffs">
<thead>
<tr class="tblhead">
<th>AM</th>
<th>Qualified Prospect</th>
<th>Unqualified Prospect</th>
<th>Contacted</th>
<th>Converted To Account</th>
<th>Pending Integration</th>
<th>Revenue Generating</th>
</tr>
</thead>
<tbody>
$totalCount should be a collection of $person
@foreach ($totalCount as $name => $totals)
<tr>
<td>
{{$name}}
<br>
<a href="#">Closed</a>
</td>
@include('partial.item', 'count' => $totals->qualifiedProspectCount)
@include('partial.item', 'count' => $totals->unqualifiedProspectCount)
@include('partial.item', 'count' => $totals->contactedCount)
@include('partial.item', 'count' => $totals->convertedToAccountCount)
@include('partial.item', 'count' => $totals->pendingIntegrationCount)
@include('partial.item', 'count' => $totals->revenueGeneratingCountCount)
</tr>
@endforeach
</tbody>
partial/item.blade.php
@if($count > 0)
<td><a href="#">{{{$count}}}</a></td>
@else
<td> </td>
@endif
编辑
所以这会让你以后陷入各种麻烦,但现在就开始吧。
@foreach ($totalCount as $name => $count)
<tr>
<td>
{{$name}}
<br>
<a href="#">Closed</a>
</td>
@if(isset($count[2]))
<td><a href="#">{{ $count[2] }}</a></td>
@else
<td> </td>
@endif
@if(isset($count[1]))
<td><a href="#">{{ $count[1] }}</a></td>
@else
<td> </td>
@endif
// and so on ...
</tr>
@endforeach
我建议您检查一下 Laravel's Documentation,有很多方法可以完成您正在尝试做的事情,这些方法比您正在做的事情要容易得多。虽然感觉快了点。不是。