加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – CodeIgniter / jQuery – 分页 – 无尽的分页

发布时间:2020-12-13 16:18:51 所属栏目:PHP教程 来源:网络整理
导读:我试图将这里发现的无限分页 jquery插件( https://github.com/jney/jquery.pageless)实现到我的codeigniter项目中. 我输入的jquery代码与演示页面上的whats相同 $('#results').pageless({ totalPages: 10,url: '/theurl/index',loaderMsg: 'Loading more res
我试图将这里发现的无限分页 jquery插件( https://github.com/jney/jquery.pageless)实现到我的codeigniter项目中.

我输入的jquery代码与演示页面上的whats相同

$('#results').pageless({ totalPages: 10,url: '/theurl/index',loaderMsg: 'Loading more results'
});

我在codeigniter控制器中的代码如下

$config['base_url'] = base_url() . 'theurl/index';
    $config['total_rows'] = $this->model->record_count();
    $config['per_page'] = 20;
    $config['uri_segment'] = 3;

    // Init the config
    $this->pagination->initialize( $config );

    // Create pagination
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data['results'] = $this->onyafeet->fetch_results($config['per_page'],$page);
    $data['links'] = $this->pagination->create_links();

    // Load the view and pass through all the data
    $this->load->view('theurl/index',$data);

当我运行代码并到达页面底部时,它确实有效,但它也会将输入页面加载到它为结果创建的新div中.

任何帮助将不胜感激.

干杯

解决方法

也许您应该将结果加载到局部视图中,否则您将再次加载整个页面.创建部分视图以加载所有数据,然后将部分视图加载到主页面:

$config['base_url'] = base_url() . 'theurl/index';
$config['total_rows'] = $this->model->record_count();
$config['per_page'] = 20;
$config['uri_segment'] = 3;

// Init the config
$this->pagination->initialize( $config );

// Create pagination
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['results'] = $this->onyafeet->fetch_results($config['per_page'],$page);
$data['links'] = $this->pagination->create_links();
// AJAX load: 
if ($this->input->is_ajax_request) {
    $this->load->view('theurl/partial/ajax_partial',$data);
}
else {
    // Load the view and pass through all the data
    $this->load->view('theurl/index',$data);
}

我认为使用这种方法应该有效,部分视图必须只有你想要显示的正确部分,div包含你想要异步加载的所有内容.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读