目前我正在使用SS4博客模块。 我们使用了分页式的博客。 p>
现在我们需要为更多内容加载更多ajax。 p>
如何在SS4中执行此操作? p>
I 我正在寻找一个这样的例子,但社区无法给我答案。 p> div>
Currently I am using SS4 Blog module. We have used a paginated style of blog.
And now we need a load more ajax for more content.
Any idea on how to do this in SS4?
I am searching for an example of this but the community was not able to give me an answer.
目前我正在使用SS4博客模块。 我们使用了分页式的博客。 p>
现在我们需要为更多内容加载更多ajax。 p>
如何在SS4中执行此操作? p>
I 我正在寻找一个这样的例子,但社区无法给我答案。 p> div>
Though your question is not clear, I will try to answer it in the way I think will make sense.
Pagination: This view is like a book were you actually have to flip through each "Page". If you are on Page 2, you won't see what's on Page 1.
LoadMore: You start on Page 1 then you append results of Page 2 to the View where Page 1 is. This way you can view Page 1 and Page 2 on the same Page creating a stack of pages.
For LoadMore which you asked.
You need a js variable var currentPage = 1;
to hold the current page to be loaded from the server. Each time you request data you will need to provide the current page you are on. Logically something like this
var url = 'server.com/posts/pull?page='+currentPage;
PostsController.php
add the method name to the allowed-action
private static $allowed_actions = [
'pull',
];
Create a method called "pull" with the code below in it.
$oListings = BlogPost::get();
$oList = new PaginatedList( $oListings, $this->request );
$oList->setPageLength( $limit );
$oList->setCurrentPage( $page );
Lastly your routes.yml (simplified)
SilverStripe\Control\Director:
rules:
'posts//$Action/$ID/$OtherID': 'PostsController'
Lastly using jQuery you can APPEND [http://api.jquery.com/append/] to add more content to your page.
Hope this helps
报告相同问题?