2012-07-11 19 views
0

在jQuery插件,jPaginate,子對象的數量是(線45-48在jPaginate.js)總返回由該代碼確定的值1:jPaginate獲得不正確子計數

//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功能:

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

和我包裹ID =「內容」一個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> 

我得到的是一頁長的記錄,分頁選擇器設置爲'上一個''下一個'。我三倍檢查,取代&,並盡我所能調試代碼。我現在還不能確定爲什麼number_of_items被設置爲1

任何幫助表示讚賞。 謝謝。

回答

0

答案是由於選擇器。

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

OBJ#內容,你的被傳遞到插件。所以obj.children()只返回第一個孩子,,在obj內。由於數組中只有一個項目,所以它的大小爲1.

+0

我嘗試將ID放在表格元素上。那也行不通。但桌子上會有所有的孩子,對吧?或者表格元素不能接受ID。任何想法如何糾正? – 2012-07-11 20:12:14

+0

我會給你信貸。由於時間限制,我選擇了一個不太優雅的解決方案。如果我有機會,我會執行此操作。 – 2012-07-12 14:20:59