【问题标题】:CodeIgniter / jQuery - Pagination - Endless PaginationCodeIgniter / jQuery - 分页 - 无休止的分页
【发布时间】:2012-10-23 07:16:36
【问题描述】:

我正在尝试将此处找到的无限分页 jquery 插件 (https://github.com/jney/jquery.pageless) 实现到我的 codeigniter 项目中。

我输入的jquery代码和演示页面上的一样

$('#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 中。

任何帮助将不胜感激。

干杯

【问题讨论】:

  • 您的意思是“整个”页面,对吗?那么,在您的视图中,正在加载的究竟是什么,如果它是“整个”页面,那么这就是您在成功的分页调用时将嵌套的内容。
  • 嘿,大卫,感谢您的回复……这完全有道理……解决这个问题的最佳方法是什么?
  • 创建一个只包含需要出现在分页结果中的数据的视图,然后调用它。
  • 所以我会将其加载到配置的 base_url 中? ...我很困惑哈哈哈..有没有一些示例代码的机会?
  • Chococroc 下面的回答几乎总结了我上面的 cmets... :)

标签: php jquery codeigniter


【解决方案1】:

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

$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。

【讨论】:

  • 谢谢你......它有点工作,除了现在它加载完全相同的结果,它也不会工作,除非我循环浏览部分和非部分视图的结果:S
  • Mmm... 查看'pageless'的设置,我认为您的问题可能与您的视图标记有关:主视图('theurl/index')应该有一个标记元素您将收取下一个项目的费用。在'pageless'中,我看到你可以指定这个标记元素,也许可以设置: $('#results').pageless({ totalPages: 10 , url: '/theurl/index' , loaderMsg: 'Loading more results',容器:'#element'});并在主页面中添加
    BLABLA
    可以工作。
猜你喜欢
  • 2013-06-28
  • 1970-01-01
  • 2013-08-14
  • 2013-05-24
  • 2023-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-18
相关资源
最近更新 更多