【问题标题】:Jquery inifinte scroll not working after AJAX using Yii infinite scroller extension在使用 Yii 无限滚动器扩展的 AJAX 之后,Jquery 无限滚动不起作用
【发布时间】:2014-04-16 13:16:57
【问题描述】:

在使用 Yii 无限滚动扩展的 AJAX 之后,Jquery inifinte 滚动不起作用。请在下面查看我的代码

post.php

class PostController extends Controller
{
     public function actionIndex()
     {
        $criteria = new CDbCriteria;
        $total = Post::model()->count();

        $pages = new CPagination($total);
        $pages->pageSize = 20;
        $pages->applyLimit($criteria);

        $posts = Post::model()->findAll($criteria);

        $this->render('index', array(
            'posts' => $posts,
            'pages' => $pages,
        ));
     }
}

查看.php

    <script src="<?php echo Yii::app()->request->baseUrl; ?>/themes/front/assets/plugins/jquery-1.10.1.min.js" type="text/javascript"></script> 
   function Sort(){
$('#LoadingImage').show();
$.ajax({
    type:'post',
    url: '<?php echo Yii::app()->createUrl('index.php/site/Sort')?>',
    data: "",
    success: function(response){
        $("#posts").replaceWith(response);
    },         
});
}
<div id="posts">
 <?php foreach($posts as $post): ?>
   <div class="post">
      <p>Autor: <?php echo $post->author; ?></p>
      <p><?php echo $post->text; ?></p>
   </div>
<?php endforeach; ?>
</div>
<?php $this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(
    'contentSelector' => '#posts',
    'itemSelector' => 'div.post',
    'loadingText' => 'Loading...',
    'donetext' => 'This is the end... my only friend, the end',
    'pages' => $pages,
 )); ?>

到目前为止,它工作正常,并且项目正在滚动加载。 但我有基于类别的帖子的ajax排序。帖子在哪里加载但无限滚动不起作用?

我有如下的 renderPartial 号召性用语

public function actionSort()
{
        $criteria = new CDbCriteria;
        $criteria->order = ' id desc';
        $total = Post::model()->count();

        $pages = new CPagination($total);
        $pages->pageSize = 20;
        $pages->applyLimit($criteria);

        $posts = Post::model()->findAll($criteria);

    $this->renderPartial('_index', array(
            'posts' => $posts,
            'pages' => $pages,false,true
        ));
}

我的渲染局部视图如下 _index.php

<div id="posts">
 <?php foreach($posts as $post): ?>
   <div class="post">
      <p>Autor: <?php echo $post->author; ?></p>
      <p><?php echo $post->text; ?></p>
   </div>
<?php endforeach; ?>
</div>
<?php $this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(
    'contentSelector' => '#posts',
    'itemSelector' => 'div.post',
    'loadingText' => 'Loading...',
    'donetext' => 'This is the end... my only friend, the end',
    'pages' => $pages,
 )); ?>

AJAX 排序后无限滚动不起作用 http://www.yiiframework.com/extension/yiinfinite-scroll/

【问题讨论】:

    标签: yii infinite-scroll


    【解决方案1】:

    这样写:

    $this->renderPartial('_index', array(
            'posts' => $posts,
            'pages' => $pages),false,true
        );
    

    而不是这个:

    $this->renderPartial('_index', array(
            'posts' => $posts,
            'pages' => $pages,false,true
        ));
    

    【讨论】:

    • $pages 后面的“)”右括号有什么用?
    猜你喜欢
    • 2013-07-05
    • 1970-01-01
    • 2015-07-25
    • 2017-03-27
    • 2013-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多