使用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,
));
}
}
View.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排序。帖子加载但是infinte滚动不起作用?
我对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/
答案 0 :(得分:-1)
写下这个:
$this->renderPartial('_index', array(
'posts' => $posts,
'pages' => $pages),false,true
);
而不是:
$this->renderPartial('_index', array(
'posts' => $posts,
'pages' => $pages,false,true
));