【问题标题】:jPaginate obtains incorrect child countjPaginate 获得不正确的子项计数
【发布时间】:2012-07-12 03:19:56
【问题描述】:

在 jQuery 插件 jPaginate 中,子对象的数量始终返回由此代码确定的值 1(jPaginate.js 中的第 45-48 行):

//getting the amount of elements inside parent element
var number_of_items = obj.children().size();
//calculate the number of pages we are going to have
var number_of_pages = Math.ceil(number_of_items/show_per_page);

我在 document.ready 函数的 header 中调用脚本:

$("#content").jPaginate({
items: 4,
pagination_class: "pagination",
minimize: true                    
});

然后我将一个 id="content" 的 div 包裹在我想要这样分页的表格行周围:

    <div id="content">
        <table class="stripeMe center box-shadow-inner">
            <?php foreach ($invoices as $invoice) { ?>
                <tr>
                    <td>
                        <a href='<?php echo $_SERVER['PHP_SELF']; ?>/retrieve?class=InvoiceLineItems&amp;id=<?php echo $invoice['invoice_id']; ?>'><?php echo $invoice['invoice_number']; ?></a>&nbsp;<?php echo $invoice['customer_name'] ?>&nbsp;<?php echo $invoice['invoice_date'] ?> 
                    </td>
                </tr>   
            <?php } ?>    
        </table>
    </div>

我得到的是一长页记录,分页选择器设置为“上一个”1“下一个”。我尽可能地检查、删除和替换代码并调试了三倍。我仍然无法确定为什么 number_of_items 被设置为 1。

感谢任何帮助。 谢谢。

【问题讨论】:

    标签: jquery jquery-plugins


    【解决方案1】:

    答案是由于选择器。

    var number_of_items = obj.children().size();
    

    obj 是您传递给插件的 #content。所以 obj.children() 只返回 obj 中的第一个孩子 table。由于数组中只有一项,因此它的大小为 1。

    【讨论】:

    • 我尝试将 ID 放在表格元素上。那也没用。但是桌子上会有所有的孩子,对吧?或者表格元素可以不接受 ID。有关如何纠正此问题的任何想法?
    • 我会给你功劳。由于时间限制,我选择了一个不太优雅的解决方案。如果有机会,我会实施。
    猜你喜欢
    • 2021-10-21
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多