doulan1866 2015-12-11 08:53
浏览 62

yii2 nirvana infinitescroll pager无法正常工作

I used yii 2.0. I displayed the list using data provider. For this i integrate the infinite scroll pagination.

Below is my code:

echo yii\widgets\ListView::widget([
 'id' => 'my-listview-id',
 'dataProvider' => $listDataProvider,
 'itemView' =>'_item_view',
 'pager' => [
    'class' => nirvana\infinitescroll\InfiniteScrollPager::className(),
    'widgetId' => 'my-listview-id',
    'itemsCssClass' => 'test',
]

 ]);

Here the first 10 records displayed fine. Then the "Load More" button is displayed. But nothing is loaded. The infinite scroll is not working.

while viewing the source code the following script is displayed at the footer.

<script type="text/javascript">$('#my-listview-id .test').infinitescroll({"maxPage":5,"contentSelector":"#my-listview-id .test","itemSelector":"#my-listview-id .test >","navSelector":"#my-listview-id ul.pagination","nextSelector":"#my-listview-id ul.pagination li.next a:first","loading":{"img":"/fancytemple_blog/assets/a7b78b36/ajax-loader.gif"}}, ,);</script>

In console the script error shown is Uncaught SyntaxError: Unexpected token ,

Anybody will help to fix this. Thanks

  • 写回答

2条回答 默认 最新

  • douzhimao8656 2015-12-11 15:08
    关注

    Your code looks fine but I checked your generated javascript against mine and it's different, I think because I've used more plugin options. So that could be a possible solution.

    <?=
    ListView::widget([
        'id' => 'feed',
        'dataProvider' => $dataProvider,
        'layout' => "{summary}
    <div class=\"items\">{items}</div>
    {pager}",
        'itemView' => '_itemview',
        'summary' => '',
        'emptyText' => $emptyText,
        'pager' =>
        ['class' => 
    irvana\infinitescroll\InfiniteScrollPager::className(),
            'widgetId' => 'feed',
            'itemsCssClass' => 'items',
            //'contentLoadedCallback' => 'function(id, data) {$("time.timeago").timeago();}',
            'pluginOptions' => [
                'loading' => [
                    'msgText' => "<center><img src='/loading.gif'></center>",
                    'img' => "/1x1-pixel.png",
                    'finishedMsg' => $emptyText,
                ],
            //'behavior' => 
    irvana\infinitescroll\InfiniteScrollPager::BEHAVIOR_TWITTER,
            ],
        ]
    ]);
    ?>
    

    If adding the extra options doesn't work then try making sure you're running the latest version and try using it on a page with nothing else there to make sure there's nothing messing with. Hope this helps.

    Another idea is to make sure pagination is set in your dataprovider, take the infinite scroll out and make sure pagination is ok, if it works then you know it's an issue with the infinite scroll and not something else.

    $dataProvider = new ActiveDataProvider([
      'query' => $query,
      'pagination' => ['pageSize' => '10']]); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序