模态内的不同输出(Laravel 5.4)
Different output inside modal (Laravel 5.4)
我的 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 升级一个模式。如果您在写作方面需要帮助,请给我留言
我的 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 升级一个模式。如果您在写作方面需要帮助,请给我留言