【发布时间】:2014-05-31 04:42:32
【问题描述】:
到目前为止,我可以通过设置静态限制来加载结果。但是为了我的目的,我需要这个限制可以由一个函数来设置,该函数每次有一个新的调用以获得更多结果时都会生成一个介于 2-8 之间的数字(我已经做了那个函数,但不知道它在代码中的位置)
function random_cols () {
$min_cols=2;
$max_cols=8;
$cols = array();
$n = rand($min_cols,$max_cols);
array_push($cols, $n);
$var = 12 - $n;
while ($var>0) {
$n = rand($min_cols,$var);
if ($var-$n<=1) {
$n = $var;
}
$var = $var - $n;
array_push($cols, $n);
}
return $cols;
}
$mylimit_arr = random_cols ();
$mylimit = count($mylimit_arr);
控制者:
public $paginate = array(
'limit' => $mylimit,
'order' => array('Post.id' => 'asc' ),
);
public function index() {
$posts = $this->paginate('Post');
$this->set('posts', $posts);
}
查看(使用无限滚动插件):
<div id="posts-list">
<div class="post-item"></div>
</div>
<script>
$(function(){
var $container = $('#posts-list');
$container.infinitescroll({
navSelector : '.next', // selector for the paged navigation
nextSelector : '.next a', // selector for the NEXT link (to page 2)
itemSelector : '.post-item', // selector for all items you'll retrieve
debug : true,
dataType : 'html',
loading: {
finishedMsg: 'No more posts to load. All Hail Star Wars God!',
img: '<?php echo $this->webroot; ?>img/spinner.gif'
}
}
);
});
</script>
您可能想知道我为什么需要它,但这是因为设计和我显示结果的方式
【问题讨论】:
标签: jquery ajax twitter-bootstrap cakephp pagination