【问题标题】:twbs pagination not displaying datatwbs分页不显示数据
【发布时间】:2019-02-08 15:54:36
【问题描述】:

我的 html 标头:

    <link rel='stylesheet' href='/stylesheets/style.css' />
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
   <script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   <!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> -->
   <script src="https://cdnjs.cloudflare.com/ajax/libs/twbs-pagination/1.4.1/jquery.twbsPagination.min.js"></script>
   <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

jquery:

function apply_pagination() {
            console.log("apply_pagination called")
            console.log("total pages", totalPages)
            $pagination.twbsPagination({
                totalPages: totalPages,
                visiblePages: 6,
                onPageClick: function (event, page) {
                    displayRecordsIndex = Math.max(page - 1, 0) * recPerPage;
                    endRec = (displayRecordsIndex) + recPerPage;
                    displayRecords = records.slice(displayRecordsIndex, endRec);
                    console.log("i am inside onpageclick");
                    generate_table();
                }
            });
        }

html:

   <div class="container">                                                                               
    <div class="table-responsive">   
    <h2>View Installment Details</h2>     
    <table class="table">
        <tbody id="emp_body">
            <tr>
                <th>Customer ID</th>
            </tr>
            <tr>
                <th>Transaction ID</th>
            </tr>
            <tr>
                <th>First Due Amount</th>
            </tr>
            <tr>
                <th>First Due Date</th>
            </tr>
            <tr>
                <th>Second Due Amount</th>
            </tr>
            <tr>
                <th>Second Due Date</th>
            </tr>
        </tbody>
    </table>
    <div id="pager">
        <ul id="pagination" class="pagination-lg"></ul>
    </div>
    </div>
  </div>

onPageClick 中的 console.log 没有被调用。有什么原因吗?它适用于我的暂存环境,但不适用于生产环境。

编辑: 添加了用于分页的 html 代码。它在分期中运行良好,但在生产中运行良好。

【问题讨论】:

  • $pagination 在哪里定义?控制台有错误吗?
  • var $pagination = $('#pagination') @AmmoPT
  • 但它不在提供的代码中,#paginationul 元素吗?
  • @AmmoPT 是的。 >>
    • @AmmoPT 它可能是我的 html 文件的标题,因为它包含太多 jquery 吗?

    标签: javascript jquery


    【解决方案1】:

    twbs pagination 不显示数据的原因是因为您的变量totalPages 的值为1,根据此code function

    // hide if only one page exists
    if (this.options.hideOnlyOnePage && this.options.totalPages == 1) {
        if (this.options.initiateStartPageClick) {
            this.$element.trigger('page', 1);
        }
        return this;
    }
    

    确保totalPages&gt;1,否则它不会显示任何寻呼机。

    【讨论】:

    猜你喜欢
    • 2017-11-23
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 2015-05-29
    • 1970-01-01
    相关资源
    最近更新 更多