【发布时间】:2018-10-17 06:30:05
【问题描述】:
我有一个标签字段。这些包含年份。 我需要分别显示所有这些的页码。 比如我有;
全部 - 2018 - 2017 - 2016
2018 选项卡包含 30 个值。 2017 制表符 = 15 个值。 2016 制表符 = 15 个值。 所有选项卡都包含 = 60 值。
当我单击随机选项卡时,分页号必须更改。
标签:
<ul id="tab">
<li>All</li>
<li>2018</li>
<li>2017</li>
</ul>
标签内:
<div id="wrapper">
<div class="contents">
@foreach($projects as $project)
<div>{{$project->created_at}}</div>
<div><img src="{{('/storage/'.$project->image)}}"/></div>
@endforeach
</div>
<div class="contents">
@foreach($projects2018 as $project)
<div>{{$project->created_at}}</div>
<div><img src="{{('/storage/'.$project->image)}}"/></div>
@endforeach
</div>
<div class="contents">
@foreach($projects2017 as $project)
<div>{{$project->created_at}}</div>
<div><img src="{{('/storage/'.$project->image)}}"/></div>
@endforeach
</div>
<div class="contents">
@foreach($projects2016 as $project)
<div>{{$project->created_at}}</div>
<div><img src="{{('/storage/'.$project->image)}}"/></div>
@endforeach
</div>
我创建了这个.contents 字段。
使用我的脚本代码。选项卡正在发生变化,值正在到来。 这是我的控制器:
$projects = Project::latest()->paginate(50);
$projects2018 = Project::whereYear('created_at', '=', 2018)->paginate(50);
$projects2017 = Project::whereYear('created_at', '=', 2017)->paginate(50);
$projects2016 = Project::whereYear('created_at', '=', 2016)->paginate(50);
在这种情况下,控制器只获得 50 值。之后 js 对这 50 个值进行分页。 10 x 10。我的意思是 5 有 5 页。但是所有值都在同一时间下载。单击时我需要下载页面 2-3-4-5 值。不要同时下载所有值!这很无聊。我不知道怎么做。
这也是我的 javascript 代码。
<script>
$(document).ready(function()
{
$("#tab").tabpager({
items: 10,
contents: 'contents',
time: 300,
previous: 'Geri',
next: 'İleri',
start: 1,
position: 'top',
scroll: true
});
});
仍然想知道解决方案...
【问题讨论】:
标签: javascript laravel pagination tabs eloquent