2012-07-23 22 views
1

我有一個非常大的itens列表,我想在使用sencha touch的移動應用程序中顯示。該列表已分頁,用戶可以從任何頁面開始查看。 Sencha Touch 2有一個非常好的分頁商店,並且該列表有一個ListPaging插件,它有助於在商品末尾加載新的itens。我正在嘗試改編此插件,以便可以從以前的頁面加載itens。問題是:在我用前一頁重新加載商店之後,如果我將'clearOnPageLoad'配置選項設置爲false,那麼新的itens會附加到列表中,而不是放在開始處。我找不到任何方法來改變這種行爲。任何幫助表示讚賞。如何在使用商店加載前一頁後將itens添加到Sencha Touch 2列表的開頭?

+0

Hi.Am面臨同樣的問題。你能分享你的代碼嗎?可能幫助我。 – Khush 2012-07-25 02:52:39

+0

我回答了我自己的問題,也許只是對您的商店進行整理就足夠了。 – 2012-07-25 17:42:42

回答

0

稍微閱讀了Store.js代碼之後,我現在明白會發生什麼:對previousPage的調用只是對loadPage(currentPage - 1)的調用,並且它僅更改ajax調用的參數,因此數據刷新無法知道新數據是應放在當前頁面之前還是之後。

「doDataRefresh」方法是您在更新商店時內部調用的方法。如果addRecords設置爲false,則此方法在加載新數據時清除內部數據數組。如果將其設置爲true,它只是將數據添加到結束:

 ... (internals of doDataRefresh) 
     if (operation.getAddRecords() !== true) { 
     for (i = 0; i < ln; i++) { 
      record = currentRecords[i]; 
      record.unjoin(me); 

      // If the record we are removing is not part of the records we are about to add to the store then handle 
      // the destroying or removing of the record to avoid memory leaks. 
      if (records.indexOf(record) === -1) { 
       if (syncRemovedRecords && record.phantom !== true) { 
        removed.push(record); 
       } 
       else if (destroyRemovedRecords && !syncRemovedRecords && !record.stores.length) { 
        record.destroy(); 
       } 
      } 
     } 
     data.clear(); 
     // This means we have to fire a clear event though 
     me.fireEvent('clear', me); 
    } 

    if (records && records.length) { 
     // Now lets add the records without firing an addrecords event 
     me.suspendEvents(); 
     me.add(records); 
     me.resumeEvents(); 
    } 

要徹底解決這個問題,你可以覆蓋存儲方法,以便:

  • 的調用「|上一頁」不斷追蹤新數據應放在當前數據之前
  • 更改doDataRefresh,以便根據標誌決定是否應在當前商店項目之前或之後添加新數據。

但是,我結束了對商店的分類 - 這對我的用例來說已經足夠了。

相關問題