2011-12-22 17 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変数を読むのは正しい範囲にはありません。 これを行うには簡単な方法が必要です。 ありがとうございます。

Greetz ジル

答えて

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

関連する問題