2011-12-22 119 views
2

我試圖從Json-File讀取數據並將其數據輸出到Ext.List中。但我不希望所有記錄都顯示在列表中。我只想顯示前3條記錄。 我已經嘗試過啓動和限制選項,但它仍然不起作用。Sencha Touch:如何設置JsonStore中的數據限制

這裏是我的代碼

型號的一部分:

Ext.regModel('News', { 
    fields: [ 
      'title', 
      'description', 
      'guid' 
     ] 
}); 

查看:

new Ext.List({ 
    "id" : "newsOverview", 
    "store" : app.stores.newsStore, 
    "itemTpl" : "{title}", 
    "listeners" : { 
     "itemtap" : function(list, index) { 
     Ext.dispatch({ 
      "controller": 'news', 
      "action" : "showDetails", 
      "model" : Ext.ModelMgr.create(list.getStore().getAt(index).data, 'News')   
     });   
     } 
    } 
}) 

商店:

app.stores.newsStore = new Ext.data.Store({ 
    "model" : "News", 
    "pageSize" : 2, 
    "proxy" : { 
    "type" : "ajax", 
    "url" : 'includes/json/news.json', 
    "reader" : "json", 
    "operation" : { 
     "start" : 0, 
     "limit" : 2 
    } 
    }  
}); 

JSON:

[ 
    { 
    "title" : "news1", 
    "description" : "description for news 1", 
    "date" : "Mon Dec 19 2011 16:23:28 GMT+0100", 
    "guid" : "11/22/33" 
    }, 
    { 
    "title" : "news2", 
    "description" : "description for news 2", 
    "date" : "Sun Dec 18 2011 12:23:28 GMT+0100", 
    "guid" : "22/33/44" 
    }, 
    { 
    "title" : "news3", 
    "description" : "description for news 3", 
    "date" : "Sat Dec 17 2011 10:22:28 GMT+0100", 
    "guid" : "33/33/44" 
    }, 
    { 
    "title" : "news4", 
    "description" : "description for news 4", 
    "date" : "Sat Dec 17 2011 10:21:28 GMT+0100", 
    "guid" : "43/33/44" 
    } 
] 

而該列表應該只輸出news1和news2。 有誰知道如何處理? 我也試過過濾器。我試圖在那裏添加一個計數變量。但是它不在正確的範圍內讀取count變量。 必須有一個簡單的方法來做到這一點。 在此先感謝。

格爾茨 吉爾斯

回答

1

我發現了一個解決方案,這可能幫助別人了。 在我的情況下即時通訊使用一個列表。該列表有一個名爲collectData的函數,可以覆蓋它。 這裏是我的功能看起來如何

"collectData" : function(records, index) { 
    var recs = []; 
    var start = (index > records.length) ? 0 : index; 
    var limit = (start+this.limit > records.length) ? records.length : start+this.limit; 
    for(var i=start; i < limit; i++) {recs[i] = records[i]['data'];} 
    return recs; 
} 

我只是需要一個漲停屬性添加到我的列表,它是在同一水平collectData。

+0

您能否詳細說明您的答案?我面臨同樣的問題。我不確定如何爲列表實現分頁。 – Khush 2012-07-25 08:42:27

相關問題