我正在使用 ExtJS 4 并尝试将 JSON 文件加载到面板网格中。参考下面的代码:
Ext.onReady(function() {
var myStore = new Ext.data.JsonStore({
autoLoad: true,
proxy: {
type: 'ajax',
url : 'http://localhost:8180/PatientVisit/grid-patient.json',
reader: {type: 'json', root: 'patient'}
},
fields: [{name: 'PatientId', type: 'string'}, {name: 'Initial', type: 'string'}, {name: 'SCStatus', type: 'string'}, {name: 'V1Status', type: 'string'}, {name: 'V2Status', type: 'string'}]
});
var grid = new Ext.grid.GridPanel({
id: 'gridPanel',
title : 'Grid example',
width : 250,
height : 250,
renderTo : 'grid-example',
store : myStore,
columns: [
{ header: 'Patient ID',
dataIndex: 'PatientId'
}, { header: 'Initial', dataIndex: 'Initial'},
{ header: 'SCStatus', dataIndex: 'SCStatus'},
{ header: 'V1Status', dataIndex: 'V1Status'},
{ header: 'V2Status', dataIndex: 'V2Status'}
]
});
myStore.load();
});
JSON file:
{"patient":[{"PatientId":"M1000","Initial":"MAS","SCStatus":"Complete","V1Status":"Open","V2Status":"Open"},
{"PatientId":"M573","Initial":"MTZ","SCStatus":"Complete","V1Status":"Complete","V2Status":"Open"},
{"PatientId":"M634","Initial":"MTS","SCStatus":"Open","V1Status":"Open","V2Status":"Open"}
]}
它在 IE 9 中运行良好。它在 Firefox 16.x 和 Chrome 浏览器中加载一个空网格。如果上面的代码有问题,请告诉我。