dongtuan8547 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.

  • 写回答

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 = 'server.com/posts/pull?page='+currentPage;
    4. Append returned data on the current view.

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料