2011-06-12 125 views
0

我想用json數據填充Ext JS 4網格。不幸的是,不管我做什麼,它仍然是空的。 JS的函數如下所示:ExtJs 4網格沒有填充數據

function buildGrid() { 

Ext.define('Contact', { 
    extend: 'Ext.data.Model', 
    fields: ['Id', 'Name', 'State', 'Age'] 
}); 

var store = Ext.create('Ext.data.Store', { 
    model: 'Contact', 
    proxy: { 
     type: 'ajax', 
     url: 'GridData', 
     reader: { 
      type: 'json', 
      record: 'data', 
      totalProperty: 'total' 
     } 
    } 
}); 

var grid = Ext.create('Ext.grid.Panel', { 
    store: store, 
    columns: [ 
     { text: "Name", flex: 1, width: 120, dataIndex: 'Name', sortable: true }, 
     { text: "State", width: 100, dataIndex: 'State', sortable: true }, 
     { text: "Age", width: 115, dataIndex: 'Age', sortable: true }, 
    ], 
    height: 210, 
    width: 600, 
    split: true, 
    renderTo: Ext.getBody() 
}).show(); 

} 

Ext.onReady(buildGrid); 

服務器性反應是這樣的:

{"callback":"1307878654818","total":1,"data":[{"Id":"ac2bedf1-bb5c-46e0-ba50-a6628341ca25","Name":"Smith","State":"NU","Age":24}]} 

,所以它看起來OK。但網格視圖不顯示日期。

任何人都可以看到我做錯了什麼?

回答

1

您還沒有指定root屬性。嘗試

reader: { 
      type: 'json', 
      root: 'data', 
      totalProperty: 'total' 
     } 
+0

令人驚歎。就是這樣!非常感謝你! – eye 2011-06-12 14:48:31