javascript - twbs分页不显示数据

标签 javascript jquery

我的 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 代码。它在舞台上效果很好,但在制作中效果不佳。

最佳答案

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>1,否则不会显示任何寻呼机。

关于javascript - twbs分页不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52152327/

相关文章:

javascript - 如何(我可以吗?)根据请求数据在拦截内加载 Cypress fixture ?

javascript - 为什么它不起作用 : find least amount of swaps needed to make either/both array A or B uniform if possible?

jquery - W3C 验证器和 jquery

jquery - 如何响应式地限制元素的数量

javascript - 如何从图像源字符串中获取源的一部分?

jquery - 如何在 iOS Web 应用程序中禁用橡皮筋?

javascript - 为什么这个循环不执行我可以手动执行的操作?

javascript - 即时更改所见即所得的文本方向(ltr 和 rtl)

javascript - 如何查看网站的 Javascript 堆栈?

javascript - 通过 jQuery 提交表单时 Required 不起作用?