【问题标题】:angularjs and codeigniter paginationangularjs和codeigniter分页
【发布时间】:2016-12-16 15:16:27
【问题描述】:

我将 angularjs 用于 UI,将 codeigniter 用于后端(REST 服务器)。当我只使用 codeigniter 时,我知道如何进行分页,但我可以弄清楚如何应对这种情况。为此,我制作了一个函数来测试它。

所以我在 REST 服务器(codeigniter)上创建了测试功能:

    $this->load->library('pagination');

    $config['base_url'] = 'http://localgost/test';
    $config['total_rows'] = 200;
    $config['per_page'] = 20;

    $this->pagination->initialize($config);

    $links = $this->pagination->create_links();
    $this->response($links, REST_Controller::HTTP_OK);

在 UI 端(angularjs)我得到了 HTTP 请求的字符串:

<strong>1</strong><a href="http://localhost/test/20" data-ci-pagination-page="2">2</a><a href="http://localhost/test/40" data-ci-pagination-page="3">3</a><a href="http://localhost/test/20" data-ci-pagination-page="2" rel="next">&gt;</a><a href="http://localhost/test/180" data-ci-pagination-page="10">Last &rsaquo;</a>

但我不知道如何将此字符串转换为分页按钮。

有谁知道我如何做到这一点,如果可能的话?如果我通过此测试成功,我将轻松为我的所有页面进行分页。

【问题讨论】:

    标签: angularjs codeigniter pagination codeigniter-restserver


    【解决方案1】:

    我也遇到了同样的问题,我用jquery解决了:

    创建一个div标签来显示分页按钮

    <div class="pagination"></div>
    

    并使用jquery:

    jQuery('.pagination').html(data.pages);
    

    在 codeigniter 中尝试使用 angular url 作为 base_url :

    $config['base_url'] = '#/users;
    $config['total_rows'] = 100;
    $config['per_page'] = 10; 
    $config['use_page_numbers'] = TRUE;
    $config['uri_segment'] = 4;
    

    【讨论】:

    • 这段jQuery代码是在哪里写的?在角度视图中,角度控制器,以及如何?你能告诉我那部分代码吗,因为我理解除了 jQuery 之外的其余部分。
    • @sasa 在从服务器获得响应后在角度控制器中
    • 我这样做了,但我总是让首页处于活动状态,当我点击另一个页面时,我更改了我的 URL,但首页仍然处于活动状态并且没有链接?
    • $config['uri_segment'] = 4;此值因您的网址而异
    • 它不起作用。我也不能使用 html(data.pages) 原因是未定义的。我只使用 html(数据)。我是否给予良好的回应,首先创建链接然后回应?你能把你的代码上传到某个地方吗?
    猜你喜欢
    • 1970-01-01
    • 2014-09-25
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    相关资源
    最近更新 更多