如何在该标签中点击分页链接时激活标签?

时间:2018-04-26 19:25:27

标签: php jquery laravel bootstrap-4

当用户访问" http://proj.test/user/profile?user=1"他进入下面的页面,其中有3个标签,一个用于用户编辑他的帐户,其他(我的门票)供用户访问有关他在会议中注册的信息以及其他(我的大会)供用户访问信息由他创建的大会。此页面访问"编辑用户帐户"。

时的默认选项卡

enter image description here

tab1内容​​供用户编辑其个人资料。当用户点击"更新"代码转到UserController以更新用户信息。

当用户点击tab2(我的票证)时,此选项卡的内容如下所示。它显示了用户会议中的注册。在此选项卡内容中,它还显示2个选项卡,供用户在已完成的大会中显示其注册,以及其他选项卡,以显示他在尚未执行的大会中的注册。

如果有超过5个结果,那么当用户更改为链接" 2"他去了" http://proj.test/user/profile?page=2"。

enter image description here

当用户点击tab3(我的会议)时,此选项卡的内容如下所示。它显示了用户创建的大会。在此选项卡内容中,它还显示3个选项卡,一个(草稿)供用户显示由他创建的具有列" status" as" D",other(已发布)以显示用户创建的具有列" status"作为" P"和其他(已存档)显示已完成的用户创建的大会。

如果有超过5个结果,那么当用户更改为链接" 2"他去了" http://proj.test/user/profile?page=2"。

enter image description here

的疑问:

此上下文的问题是,当在某个标签中单击分页链接时,例如,如果用户位于选项卡"草稿"内部"我的大会"选项卡,以及分页链接中的点击次数" 2",网址将更改为" http://proj.test/user/profile?page=2"但是第一个变为活动的标签,"编辑用户帐户"标签。然后,如果用户点击"我的大会"它出现在第2页的结果中,但用户需要手动点击"我的大会"。

在这种情况下,你知道如何转变我的大会"在"我的大会"中点击分页页面链接时,标签处于活动状态标签

此页面上的完整代码显示所有标签:

<ul class="nav nav-pills" role="tablist">
    <li class="">
        <a class="nav-link active" href="#updateUserInfo" data-toggle="tab" role="tab">Edit user account</span></a>
    </li>
    <li class="disabled">
        <a class="nav-link" href="#myCongresses" data-toggle="tab" role="tab">My Congresses</span></a>
    </li>
    <li class="disabled">
        <a class="nav-link" href="#myTickets" data-toggle="tab" role="tab">My Tickets</a>
    </li>
</ul>

<div class="tab-content" id="myTabContent">
    <div class="tab-pane fade show active clearfix" id="updateUserInfo" role="tabpanel" aria-labelledby="home-tab">
        <form method="post" action="{{route('user.updateUserInfo')}}" class="clearfix">
            {{csrf_field()}}
            <div class="form-row">
                <div class="form-group">
                    <label for="name">Name</label>
                    <input type="text" value="{{$user->name}}" name="name" class="form-control" id="name" >
                </div>
               <!--other form fields-->
            <input type="submit" class="btn btn-primary btn" value="Update"/>
        </form>
    </div>

    <div class="tab-pane clearfix fade" id="myCongresses" role="tabpanel" aria-labelledby="contact-tab">
            <ul class="nav nav-pills">
                <li class="nav-item">
                    <a class="nav-link active border" href="#draftCongresses" data-toggle="tab"
                       role="tab">Draft</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link border" href="#publishedCongresses" data-toggle="tab"
                       role="tab">Published</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link border" href="#archivedCongresses" data-toggle="tab"
                       role="tab">Archived</a>
                </li>
            </ul>
        <div class="tab-content bg-white" id="myTabContent">
            <div class="tab-pane fade active show clearfix" id="draftCongresses" role="tabpanel" aria-labelledby="home-tab">
                <ul class="list-group">
                    @foreach($draftCongresses as $draftCongress)
                        @if(!empty($draftCongress))
                            <li class="list-group-item">
                                <p>{{$draftCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
                                <h5>{{$draftCongress->name}}</h5>
                                <a href="{{route('congress.edit', ['id' => $draftCongress->id])}}" class="btn">Edit Congress</a>
                            </li>
                        @endif
                    @endforeach
                </ul>
                <div class="text-center d-flex justify-content-center mt-3">
                    {{$draftCongresses->links(("pagination::bootstrap-4"))}}
                </div>
            </div>

            <div class="tab-pane fade show clearfix" id="publishedCongresses" role="tabpanel" aria-labelledby="home-tab">
                <ul class="list-group">
                    @foreach($publishedCongresses as $publishedCongress)
                        @if(!empty($publishedCongress))
                            <li class="list-group-item">
                                <p>{{$publishedCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
                                <h5>{{$publishedCongress->name}}</h5>
                                <a href="{{route('congress.edit', ['id' => $publishedCongress->id])}}"
                                   class="btn btn-outline-primary">Edit Congress</a>
                            </li>
                        @endif
                    @endforeach
                </ul>
                <div class="text-center d-flex justify-content-center mt-3">
                    {{$publishedCongresses->links(("pagination::bootstrap-4"))}}
                </div>
            </div>

            <div class="tab-pane fade show clearfix" id="archivedCongresses" role="tabpanel" aria-labelledby="home-tab">
                <ul class="list-group">
                    @foreach($archivedCongresses as $archivedCongress)
                        @if(!empty($archivedCongress))
                            <li class="list-group-item">
                                <p> {{$archivedCongress->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
                                <h5>{{$archivedCongress->name}}</h5>
                                <a href="{{route('congress.edit', ['id' => $archivedCongress->id])}}"
                                   class="btn btn-outline-primary">Edit Congress</a>
                            </li>
                        @endif
                    @endforeach
                </ul>

                <div class="text-center d-flex justify-content-center mt-3">
                    {{$archivedCongresses->links(("pagination::bootstrap-4"))}}
                </div>
            </div>
        </div>
    </div>


    <div class="tab-pane clearfix fade" id="myTickets" role="tabpanel" aria-labelledby="contact-tab">

        <div class="d-flex mb-3">
            <ul class="nav nav-pills">
                <li class="nav-item">
                    <a class="nav-link active border" id="nextCongresses" href="#nextCongresses" data-toggle="tab" role="tab">Next Congresses</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link border" id="pastCongresses" href="#pastCongresses" data-toggle="tab" role="tab">Past Congresses</a>
                </li>
            </ul>
        </div>
        <div class="tab-content" id="myTabContent">
            <div class="tab-pane fade show active" id="nextCongresses" role="tabpanel" aria-labelledby="home-tab">
                <ul class="list-group" id="nextCongressesContainer">
                    @foreach($nextRegistrations as $nextRegistration)
                        @if(!empty($nextRegistration->congress || !empty($nextRegistration->congress->start_date)))
                            <li class="list-group-item">
                                <p>{{optional($nextRegistration->congress)->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
                                <h5>{{optional($nextRegistration->congress)->name}}</h5>
                                <p> Registration in {{optional($nextRegistration->congress)->created_at }}</p>
                            </li>
                        @endif
                    @endforeach
                </ul>

                <div class="text-center d-flex justify-content-center mt-3">
                    {{$nextRegistrations->links(("pagination::bootstrap-4"))}}
                </div>

            </div>

            <div class="tab-pane fade show" id="pastCongresses" role="tabpanel" aria-labelledby="home-tab">
                <ul class="list-group" id="pastCongressesContainer">
                    @foreach($pastRegistrations as $pastRegistration)
                        @if(!empty($pastRegistration->congress || !empty($pastRegistration->congress->start_date)))
                            <li class="list-group-item">
                                <p>{{optional($pastRegistration->congress)->start_date->formatLocalized('%a, %b %d, %Y - %H:%M')}}</p>
                                <h5>{{optional($pastRegistration->congress)->name}}</h5>
                                <p> Registration in   {{$pastRegistration->created_at}}</p>
                            </li>
                        @endif
                    @endforeach
                </ul>

                <div class="text-center d-flex justify-content-center mt-3">
                    {{$pastRegistrations->links(("pagination::bootstrap-4"))}}
                </div>
            </div>
        </div>
    </div>
</div>

UserController中:

class UserController extends Controller
{
    public function index(Request $request){

        $pageLimit = 5;

        $user = $request->user();

        $pastRegistrations = $user->registrations()->with(['congress' => function ($query) {
            $query->where('end_date', '<', now());
        }])->paginate($pageLimit);

        $nextRegistrations = $user->registrations()->with(['congress' => function ($query) {
            $query->where('end_date', '>', now());
        }])->paginate($pageLimit);

        $draftCongresses = $user->congresses()->where('status','D')->paginate($pageLimit);
        $pastCongresses = $user->congresses()->where('end_date','<', now())->paginate($pageLimit);
        $publishedCongresses = $user->congresses()->where('status','P')->paginate($pageLimit);

        return view('users.index',
            compact('user', 'pastRegistrations','nextRegistrations', 'draftCongresses', 'pastCongresses', 'publishedCongresses'));
    }
}

问题示例

如果分页链接&#34; 2&#34;点击此处:

enter image description here

而不是出现在&#34; My Congresses&#34;标签活动如上图所示,但带有分页链接&#34; 2&#34;积极而不是分页链接&#34; 1&#34;处于活动状态时,它会使用默认的有效选项卡&#34;编辑用户帐户&#34;:

来显示页面

enter image description here

0 个答案:

没有答案