模态内部的不同输出(Laravel 5.4) [英] Different output inside modal (Laravel 5.4)

查看:53
本文介绍了模态内部的不同输出(Laravel 5.4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的trips.blade.php中有此代码.问题是,当我的$ t->员工不在模态中时,我会检索所有员工,但是当我将我的$ t->员工放入模态中时,我只能检索1个数据.在这种情况下,我找不到任何错误.

I have this code in my trips.blade.php. The problem is when my $t->employees is outside the modal, I retrieve all my employees but when I put my $t->employees inside my modal, I can only retrieve 1 Data. I can't figure out any error in this scenario.

@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">&times;</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

屏幕截图

推荐答案

简短答案,但并非最佳做法是按以下方式更改这些行

short answer but not a best practice is to change these lines as below

 <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">

如果可行,您可以先尝试一下,然后再讨论问题.

you can try this out first if it works then lets discuss the issue.

我以前有过这种情况.在页面中发生的事情是您制作了许多行,并且在每行中创建的ID为viewEmployeesAttendanceTicket的模式,因此有许多模式都具有相同的ID为viewEmployeesAttendanceTicket,当尝试显示其中的任何一个时,它们将始终显示相同的模态-我猜是第一个-所以您在这里有两种方法.首先是如上所述区分模式,但是如果您有很多行,那么此解决方案就不是很好,因为您将有如此多的模式加载了数据.

I had that case before. what happens in your page is your making many rows and in each one you're creating modal with the id viewEmployeesAttendanceTicket so there's many modals all with the same id viewEmployeesAttendanceTicket and when trying to display any of them they will always display the same modal-the first I guess- so you've two approaches here. The first is to differentiate the modals as mentioned above but this solution is not very good if you've many rows as you'll have so many modals loaded with data.

更时尚的解决方案是让jquery升级一个模式.如果您需要编写帮助,请给我留言

the more sleek solution is to have one modal upgradable by jquery. if you need help with writing it leave me a comment

这篇关于模态内部的不同输出(Laravel 5.4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆