我成功从Controller返回数据
public function index()
{
$posts = Post::with('status' == 'verified)
->paginate(30);
return view ('show')->with(compact('posts'));
}
此外,我在视图中成功展示了所有内容:
<div id="content" class="col-md-10">
@foreach (array_chunk($posts->all(), 3) as $row)
<div class="post row">
@foreach($row as $post)
<div class="item col-md-4">
<!-- SHOW POST -->
</div>
@endforeach
</div>
@endforeach
{!! $posts->render() !!}
</div>
到目前为止,一切都很顺利。
但是,我根本没有得到官方文件。什么是&#39; div.navigation
&#39;和&#39; #content div.post
&#39;?我的情况应该是什么?
来自文档的小部件:
$('#content').infinitescroll({ navSelector : "div.navigation", // selector for the paged navigation (it will be ?>hidden) nextSelector : "div.navigation a:first", // selector for the NEXT link (to page 2) itemSelector : "#content div.post" // selector for all items you'll retrieve });
编辑:我的Javascript到目前为止
$(document).ready(function() {
(function() {
var loading_options = {
finishedMsg: "<div class='end-msg'>Congratulations! You've reached the end of the internet</div>",
msgText: "<div class='center'>Loading news items...</div>",
img: "/assets/img/ajax-loader.gif"
};
$('#content').infinitescroll({
loading: loading_options,
navSelector: "ul.pagination",
nextSelector: "ul.navigation a:first",
itemSelector: "#content div.item"
});
});
});
[&lt; [1] 2] 3]&gt;]部分创建在页面底部,但无限滚动不起作用。另外,我在控制台中没有记录或错误。
答案 0 :(得分:6)
首先,您需要在结束#content
div:
{!! $posts->render() !!}
这将输出如下内容:
<ul class="pagination"><li><a>...</a></li>
要覆盖分页演示者,请查看this answer on SO。
然后您的配置如下所示:
$(document).ready(function() {
var loading_options = {
finishedMsg: "<div class='end-msg'>Congratulations! You've reached the end of the internet</div>",
msgText: "<div class='center'>Loading news items...</div>",
img: "/assets/img/ajax-loader.gif"
};
$('#content').infinitescroll({
loading: loading_options,
navSelector: "ul.pagination",
nextSelector: "ul.pagination a:first",
itemSelector: "#content div.item"
});
});
基本上,无限卷轴会为您调用分页链接,因此需要知道所有内容的位置以便将它们组合在一起。