2019-05-07 06:24
浏览 32

在Silverstripe 4 Blog模块中加载更多Ajax

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.

图片转代码服务由CSDN问答提供 功能建议

目前我正在使用SS4博客模块。 我们使用了分页式的博客。



I 我正在寻找一个这样的例子,但社区无法给我答案。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongwen2162 2019-05-21 09:07

    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

    1. You render your page with Page1 loaded; currentPage = 1;
    2. OnClickingLoadMore button; currentPage++;
    3. Send the request via ajax. var url = ''+currentPage;
    4. Append returned data on the current view.


    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 [] to add more content to your page.

    Hope this helps

    解决 无用
    打赏 举报

相关推荐 更多相似问题