Extjs和php交互的一个问题

treesky 2009-12-28 11:40:32

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"}
]}
但是就是显示不出来,帮看看。
...全文
299 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang296264808 2011-06-20
  • 打赏
  • 举报
回复
虽然是旧贴了 但内容很好 学习
puddingtp 2010-05-28
  • 打赏
  • 举报
回复
太好了
treesky 2009-12-29
  • 打赏
  • 举报
回复
是啊,莫名其妙的可以显示了,代码没有改变,但是不能排序!谢谢楼上几位的!
xiuyouxu 2009-12-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 treesky 的回复:]
改成了四个以后也不行。就是不知道是不是我的JS代码哪里写错了。
[/Quote]
grid显示吗
jaxio 2009-12-29
  • 打赏
  • 举报
回复
这样试试:
 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的使用方法
treesky 2009-12-29
  • 打赏
  • 举报
回复
改成了四个以后也不行。就是不知道是不是我的JS代码哪里写错了。
xiuyouxu 2009-12-29
  • 打赏
  • 举报
回复
fields:[
{name: 'stock_code', type: 'string'},
{name: 'stock_name', type: 'string'},
{name: 'stime', type: 'string'},
{name: 'close', type: 'float'}
]
只有四个,但是数据里超过四个,还能解析吗?

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧