2010-10-24 52 views
1

我試圖將一些簡單的數據導入到JsonStore中,但它似乎不起作用。代碼與示例幾乎相同:將數據加載到JsonStore中

var itemListStore = new Ext.data.JsonStore({ 
    url: '/items/list', 
    root: 'items', 
    fields: [ 
     {name: 'id', type: 'string'}, 
     {name: 'name', type: 'string'}, 
    ] 
}); 
itemListStore.load(); 
... 
     items: [ 
     { 
     xtype: 'listview', 
     store: itemListStore, 
     columnResize: false, 
     flex: 1, 
     columns: [ 
      {header: 'ID', dataIndex: 'id'}, 
      {header: 'Name', dataIndex: 'name'}, 
     ] 
     } 
... 

不幸的是,這不起作用。該表加載時沒有行,並且存儲上的計數是68(由服務器返回,通過listview.getStore().getCount()得到)。如果我用一個ArrayStore和一些靜態數據替換JsonStore,我可以看到它們。

/items/list結果就是:

{"items": 
    [{"id": "a", "name": "Some name"}, 
    {"id": "b", "name": "Some other name"}] 
} 

我該如何解決這個問題?我怎樣才能調試呢?

編輯:已更新記錄計數

+0

如果從控制檯你Ext.getCmp('yourlistview')。getStore()。reload(),你能看到XHR返回嗎? – Orbit 2010-10-24 17:20:35

+0

@Brandon - 當我運行這個時,我返回undefined,但通過網絡發出正確的請求(根據螢火蟲)。 – viraptor 2010-10-24 17:30:24

+1

如果將xtype更改爲網格,它可以工作嗎? ;) – Orbit 2010-10-24 17:52:06

回答

2

,你可以嘗試用這樣的店的信息:

  store: objPlanManagerStore = new Ext.data.Store({ 
       autoLoad: true, 
       proxy: new Ext.data.HttpProxy({ 
        url: '/your/url', 
        method: 'POST' 
       }), 
       reader: new Ext.data.JsonReader({ 
        root: 'plans', 
        id: 'id', 
        fields: ['id', 'name', 'descr', 'tname', 'type', 'recurring'] 
       }), 
       listeners: { 
        loadexception: function() { 
         Ext.Msg.alert('Title', 'msg'); 
        } 
       } 
      }); 

(只是從我的一些代碼粘貼)

編輯:思考它,但商店似乎並不是問題。

+0

也請求正確的數據,但是我看不到任何結果,異常窗口沒有顯示出來 – viraptor 2010-10-24 17:49:43

+0

已被接受爲答覆。對於來自Orbit的真實答案,請檢查問題評論。 – viraptor 2010-11-25 02:39:25