【发布时间】:2021-02-23 05:55:17
【问题描述】:
此代码正在运行:
<table class="rounded-t-lg m-5 w-5/6 mx-auto bg-gray-200 text-gray-800">
<thead class="text-left border-b-2 border-gray-300">
<th class="px-4 py-3">#</th>
<th class="px-4 py-3">Tipo Doc.</th>
<th class="px-4 py-3">Documento</th>
<th class="px-4 py-3">Nombre</th>
<th class="px-4 py-3">Teléfono</th>
<th class="px-4 py-3">Correo</th>
<th class="px-4 py-3">Fecha</th>
<th class="px-4 py-3">Acciones</th>
</thead>
<tbody>
@if (count($pacientes)>0)
@foreach($pacientes as $paciente)
<tr class="bg-gray-100 border-b border-gray-200">
<td class="px-4 py-3">{{$paciente->id}}</td>
<td class="px-4 py-3">{{$paciente->tipoIdentificacion}}</td>
<td class="px-4 py-3">{{$paciente->Identificacion}}</td>
<td class="px-4 py-3">{{$paciente->NombreCompleto}}</td>
<td class="px-4 py-3">{{$paciente->Telefono}}</td>
<td class="px-4 py-3">{{$paciente->Correo}}</td>
<td class="px-4 py-3">{{$paciente->created_at}}</td>
<td>
<a href="{{ url('/pacientes/' . $paciente->id . '/edit') }}">
Editar
</a>
<form action="{{ url('/pacientes/' . $paciente->id) }}" method="post">
@csrf
{{ method_field('DELETE') }}
<input type="submit" value="Borrar">
</form>
</td>
</tr>
@endforeach
@endif
</tbody>
但此表不可可重复使用。为了让它作为一个组件工作,它必须使用任意数量的标题和数据,在每一行的末尾都有一个操作按钮(编辑或删除)。我已将titles(th) 保存在一个数组中,并且它们使用foreach 正确显示,但我无法按顺序用其他数据填充表格。你能帮帮我吗?
【问题讨论】:
-
不清楚你在说什么。你认为什么是头衔,你认为什么是价值观?你能举一个输入的例子吗?旁注:你不需要
@if (count($pacientes)>0),你可以直接去foreach。如果数组中没有元素,它根本不会运行。 -
标题为:姓名、身份证、电话。值是:jhon, 8388, 900339393
-
是的,这些是值,但哪些变量被视为标题,哪些值?或者你有关联数组吗?
-
它们不是关联的,它们是 2 个独立的数组,一个带有列名,另一个带有数据
-
使用
foreach中的键,如foreach $data as $key => $value,然后访问另一个数组$otherArray[$key]中的相同键。
标签: php laravel html-table laravel-8