ExtJs 4网格没有填充数据

时间:2011-06-12 11:57:24

标签: extjs extjs4

我试图用json数据填充Ext JS 4 Grid。不幸的是,无论我做什么,它仍然是空的。 JS函数如下:

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}]}

所以它看起来不错。但是网格视图未显示日期。

任何人都可以看到我做错了什么?

1 个答案:

答案 0 :(得分:1)

您尚未指定root属性。尝试

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