请在 Ext js 中找到示例
Ext.onReady(function(){
var Grid1Store = new Ext.data.JsonStore({
fields: ['keys', 'values' ],
autoLoad: true,
data: [
{ "keys":"Key1", "values":"Value1"},
{ "keys":"Key2", "values":"Value2"},
{ "keys":"Key3", "values":"Value3"},
{ "keys":"Key4", "values":"Value4"}
]
});
var grid = new Ext.grid.GridPanel({
renderTo: Ext.getBody(),
frame: true,
title: 'Database',
width:300,
store: Grid1Store,
columns: [
{text: "Keys", dataIndex: 'keys'},
{text: "Values", dataIndex: 'values'}
]
});
});
如果要加载 json 文件,请更改网格存储代码,如下所示
var Grid1Store = new Ext.data.JsonStore({
fields: ['keys', 'values' ],
autoLoad: true,
proxy:{
type:'ajax',
url:'something.json',
reader:{
root:'users'
}
}
});