3

我一直在尝试使用此插件为 codeigniter 的分页添加无限滚动。

http://www.infinite-scroll.com

到目前为止,这是我的代码:

<script type = "text/javascript">

    $('#comments').infinitescroll({

        navSelector  : "a#next:last",    // selector for the paged navigation (it will be hidden)
        nextSelector : "a#next:last",    // selector for the NEXT link (to page 2)
                    itemSelector : "#comments"       // selector for all items you'll retrieve
              });

</script>

这是默认用法。让我们假设#comments 包含我的内容。我的分页页面看起来像这样。

http://localhost/ci/index.php/chat/load/p1u/10
http://localhost/ci/index.php/chat/load/p1u/20

等等

我什至添加了这行代码以使其工作但没有成功:

<a id="next" href="http://localhost/ci/index.php/chat/load/p1u/10">next page</a>

有任何想法吗?

4

3 回答 3

1

$config["use_page_numbers"]如果要使用 /1 /2 /3 而不是 /10 /20 /30,请切换到在 pagination.php 中使用。

于 2013-01-06T02:33:24.557 回答
1

我发现这绝对适用于 $config["use_page_numbers"] = TRUE; 但如果你要走那条路,你就必须调整你的偏移量。这就是我的工作方式:

$offset = ($this->uri->segment(2)) ? ($this->uri->segment(2) * $config["per_page"]) - $config["per_page"] : 0;
于 2013-08-04T05:26:10.097 回答
0

我对代码点火器中的滚动分页有简单的步骤,我已经检查过它工作得更好

$(window).scroll(function(){
    if  ($(window).scrollTop() == $(document).height() - $(window).height()){
        // run our call for pagination
        var table = document.getElementById("table");
        var lastRowIndex = table.rows.length-1;
        loadMore(lastRowIndex);
    }
});

function loadMore(lastRowIndex)
{
$.ajax({
    url: "http://localhost/CodeIgniter/index.php/form/loadmore",  //form is y controller
    type:'POST',
    data: "row="+lastRowIndex, // row wich is post
    success: function(data){    //here data which recevie form controller
        var json = JSON.parse(data);
        var count = json.length;
        var html;
        for( var i = 0; i < count; i++ )
        {
            html += '<tr>';
            html += '<td><input type="checkbox" name="id[]" id="id[]" class="check" value="'+ json[i].id +' "></td>';
            html += '<td>'+ json[i].id +'</td>';
            html += '<td><img src="http://localhost/CodeIgniter/upload/'+ json[i].image +'" class="img-circle" height="25" width="30"></td>';
            html += '<td> ' + json[i].firstname +'</td>';
            html += '<td> ' + json[i].middlename +'</td>';
            html += '<td> ' + json[i].lastname +'</td>';
            html += '<td> ' + json[i].address +'</td>';
            html += '<td> ' + json[i].mobile +'</td>';
            html += '<td> ' + json[i].email +'</td>';
            html += '<td> ' + json[i].gender +'</td>';
            html += '<td><a href="http://localhost/CodeIgniter/index.php/form/del/'+ json[i].id +'">Delete</a></td>';
            html += '<td><a href="http://localhost/CodeIgniter/index.php/form/edite/'+ json[i].id +'">Update</a></td>';
            html += '</tr>';
        }$("#body").append(html); //add this html to th table body which id='body'
    }   
});
}

我使用这个控制器功能

 public function loadmore()
 {
    $page=$_POST['row'];
    $per_page = 10;
    $student = $this->Form_model->getview_detail($per_page,$page);
    if($student !== FALSE)
    {
        echo json_encode($student); //send data to script
    }
}

`

这是模型

public function getview_detail($limit, $start)
{
    $this->db->limit($limit, $start);
    $query = $this->db->get('form');
    return $query->result_array();
}    
于 2016-10-03T12:07:13.020 回答