我的 trips.blade.php 中有此代码。问题是当我的 $t->employees 位于模态之外时,我检索所有员工,但是当我将 $t->employees 放入模态中时,我只能检索 1 个数据。我无法找出这种情况下的任何错误。
@foreach($trips as $t)
<tr>
<td>{{$t->id}}</td>
<td>{{$t->dateMilled_trip}}</td>
<td>{{$t->ticket->ticketNumber_ticket}}</td>
<td>{{$t->truckNumber_trip}}</td>
<td>{{$t->finalWeight_trip}}</td>
<td>
{{$t->employees}} -> Here it shows all the employees inside trip
<a class="btn btn-info btn-xs" data-toggle="modal" data-target="#viewEmployeesAttendanceTicket">View Employees Attendance</a>
<!-- Modal -->
<div class="modal fade" id="viewEmployeesAttendanceTicket" tabindex="-1" role="dialog" aria-labelledby="James Order List">
<div class="modal-dialog" role="document">
<div class="modal-content">
{{$t->employees}} ->Here it show only 1 employee data
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">{{$t->ticket->ticketNumber_ticket}} Attendances</h4>
</div>
<div class="modal-body">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Employee Name</th>
</tr>
</thead>
<tbody>
@foreach($t->employees as $emp) ->same here [1 Data only]
<tr>
<td>{{$emp->id}}</td>
<td>{{$emp->name_employee}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
<td>
<div class="btn-group" role="group" aria-label="...">
<a class="btn btn-danger btn-xs">DELETE</a>
</div>
</td>
</tr>
@endforeach
最佳答案
简短的答案,但不是最佳实践是更改这些行,如下所示
<a class="btn btn-info btn-xs" data-toggle="modal" data-target="#viewEmployeesAttendanceTicket_{{$t->id}}">View Employees Attendance</a>
<!-- Modal -->
<div class="modal fade" id="viewEmployeesAttendanceTicket_{{$t->id}}" tabindex="-1" role="dialog" aria-labelledby="James Order List">
您可以先尝试一下,如果有效,然后我们再讨论这个问题。
我以前也遇到过这样的情况。在您的页面中发生的情况是您制作了许多行,并且在每一行中都使用 id viewEmployeesAttendanceTicket
创建模态,因此有许多模态都具有相同的 id viewEmployeesAttendanceTicket
并且在尝试时要显示其中任何一个,它们将始终显示相同的模式(我猜是第一个模式),所以这里有两种方法。第一个是如上所述区分模态,但如果您有很多行,则此解决方案不是很好,因为您将有很多加载数据的模态。
更时尚的解决方案是让一个模态可通过 jquery 升级。如果您需要帮助编写它,请给我留言
关于php - 模态内部的不同输出(Laravel 5.4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43337951/