Ext.onReady(function(){
var store = new Ext.data.Store({
url:'data/income.php',
reader: new Ext.data.JsonReader({
idProperty: id,
root: 'data',
totalProperty: 'total',
fields:[
{name: 'stock_code', type: 'string'},
{name: 'stock_name', type: 'string'},
{name: 'stime', type: 'string'},
{name: 'close', type: 'float'}
]
}),
remoteSort: true
});
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{header: "代码", width: 100, sortable: true, dataIndex: 'stock_code'},
{header: "名称", width: 100, sortable: true, dataIndex: 'stock_name'},
{header: "入选日期", width: 100, sortable: true, dataIndex: 'stime'},
{header: "涨幅", width: 100, sortable: true, dataIndex: 'close'}
]);
cm.defaultSortable = false; var rsm = new Ext.grid.RowSelectionModel({
singleSelect: true
}); var grid = new Ext.grid.GridPanel({
id:'grid',
el:'stock_grid',
width:document.body.clientWidth,
height:572,
store: store,
colModel: cm,
trackMouseOver:true,
selModel: rsm,
loadMask: ({
msg: '数据加载中……'
}),
viewConfig: {
forceFit:true,
emptyText:'没有数据',
enableRowBody:true
}
});
grid.render();
store.load();
});income.php产生的json如下
{"total":20,"data":[{"id":"172","stock_code":"600859","stock_name":null,"close":"36.36","raises":"0.00","teacher":"admin123","stime":"2009-12-28","flag":"0","assessor":null,"hits":"1","state":"1","isauto":"1","ext1":"0","ext2":"0","ext3":"0","ext4":"0.00","ext5":"0.00"},{"id":"173","stock_code":"600241","stock_name":null,"close":"13.92","raises":"0.00","teacher":"admin123","stime":"2009-12-28","flag":"0","assessor":null,"hits":"1","state":"1","isauto":"0","ext1":"0","ext2":"0","ext3":"0","ext4":"0.00","ext5":"0.00"},{"id":"174","stock_code":"600243","stock_name":null,"close":"8.53","raises":"0.00","teacher":"admin123","stime":"2009-12-28","flag":"0","assessor":null,"hits":"1","state":"1","isauto":"0","ext1":"0","ext2":"0","ext3":"0","ext4":"0.00","ext5":"0.00"}
]}
但是就是显示不出来,帮看看。
{name: 'stock_code', type: 'string'},
{name: 'stock_name', type: 'string'},
{name: 'stime', type: 'string'},
{name: 'close', type: 'float'}
]
只有四个,但是数据里超过四个,还能解析吗?
proxy: new Ext.data.HttpProxy({
url:'data/income.php'
}),
reader: new Ext.data.JsonReader({
idProperty: id,
root: 'data',
totalProperty: 'total',
fields:[
{name: 'stock_code', type: 'string'},
{name: 'stock_name', type: 'string'},
{name: 'stime', type: 'string'},
{name: 'close', type: 'float'}
]
})
如果不行,你把php传过来的json数据直接赋值在js中store调用。看是否运行正常。。详细操作可参见API中jsonreader的使用方法