(急)新手学extjs,使用JsonReader读取数据,数据不显示,谢谢

ycy0111 2010-08-31 10:39:16
代码:
var store=new Ext.data.Store({
//url中的值是一个servlet
proxy:new Ext.data.HttpProxy({url:"TownCodeInfo"}),
reader:new Ext.data.JsonReader(
{root:"list"},
["id","city","towncode"]
)
});
store.load();
var grid=new Ext.grid.GridPanel({
store:store,
columns:[
{header:'id',sortable: true,dataIndex:'id'},
{header:'city',sortable: true,dataIndex:'city'},
{header:'towncode',sortable: true,dataIndex:'towncode'}
],
width:750,
height:750,
title:'data',
autoExpandColumn:'id'
});
grid.render("infodiv");


Servlet中得到的JSON数据:{"list":[{"id":"1","city":"ANTANANARIVE","towncode":"111"},{"id":"2","city":"BANGALORE","towncode":"120"},{"id":"3","city":"BANGKOK","towncode":"102"}]}


请问各位,是哪里配置错了,谢谢!
...全文
400 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hoojo 2010-08-31
  • 打赏
  • 举报
回复

var store=new Ext.data.Store({
//url中的值是一个servlet
proxy:new Ext.data.HttpProxy({url:"TownCodeInfo"}),
reader:new Ext.data.JsonReader(
{root:"list"},
Ext.data.Record.create(["id","city","towncode"])//这样看看
)
});
//store.load();移到下面去
var grid=new Ext.grid.GridPanel({
store:store,
columns:[
{header:'id',sortable: true,dataIndex:'id'},
{header:'city',sortable: true,dataIndex:'city'},
{header:'towncode',sortable: true,dataIndex:'towncode'}
],
width:750,
height:750,
title:'data',
autoExpandColumn:'id'
});
store.load();//放这里看看
grid.render("infodiv");

只要后台数据格式正确,servlet输出json用resposne.getWriter().print(输出json);

参考:http://blog.csdn.net/IBM_hoojo/archive/2010/08/27/5843408.aspx
ycy0111 2010-08-31
  • 打赏
  • 举报
回复
问题已经解决了,如果设置了autoExpandColumn:'id',则需要在columns中申明一个字段为id,也就是
columns:[
{id:'id',header:'id',sortable: true,dataIndex:'id'},
{header:'city',sortable: true,dataIndex:'city'},
{header:'towncode',sortable: true,dataIndex:'towncode'}
]
,要么就不要autoExpandColumn:'id'

kc8886 2010-08-31
  • 打赏
  • 举报
回复
那就是没有传到前台页面 应该是servlet的问题
把后台代码拿出来看看
hoojo 2010-08-31
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ibm_hoojo 的回复:]

引用 6 楼 ycy0111 的回复:

引用 5 楼 kc8886 的回复:

store.load(); 有没有放到一楼说的那个位置 另外 最好看看数据集里有没有数据 比如
store.load({callback:function(){
alert(store.getTotalCount());
}});


数据集中没有数据,弹出的提示框为0,用了 IB……
[/Quote]
注意不要跳转页面
hoojo 2010-08-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ycy0111 的回复:]

引用 5 楼 kc8886 的回复:

store.load(); 有没有放到一楼说的那个位置 另外 最好看看数据集里有没有数据 比如
store.load({callback:function(){
alert(store.getTotalCount());
}});


数据集中没有数据,弹出的提示框为0,用了 IBM_hoojo 的方法,好像也不行的
[/Quote]
哦,那就是你后台的原因了。可能是数据格式不对
servlet后台输出json用resposne.getWriter().print(输出json);

ycy0111 2010-08-31
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 kc8886 的回复:]

store.load(); 有没有放到一楼说的那个位置 另外 最好看看数据集里有没有数据 比如
store.load({callback:function(){
alert(store.getTotalCount());
}});
[/Quote]

数据集中没有数据,弹出的提示框为0,用了 IBM_hoojo 的方法,好像也不行的
kc8886 2010-08-31
  • 打赏
  • 举报
回复
store.load(); 有没有放到一楼说的那个位置 另外 最好看看数据集里有没有数据 比如
store.load({callback:function(){
alert(store.getTotalCount());
}});
hoojo 2010-08-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ibm_hoojo 的回复:]

JScript code

var store=new Ext.data.Store({
//url中的值是一个servlet
proxy:new Ext.data.HttpProxy({url:"TownCodeInfo"}),
reader:new Ext.data.JsonReader(
{root:"list"},
Ext.data.Record.create(["id",……
[/Quote]
看看2#的,行不?
var store=new Ext.data.Store({
//url中的值是一个servlet
proxy:new Ext.data.HttpProxy({url:"TownCodeInfo"}),
reader:new Ext.data.JsonReader(
{root:"list"},
Ext.data.Record.create(["id","city","towncode"])//这样看看
)
});

ycy0111 2010-08-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 kc8886 的回复:]

proxy:new Ext.data.HttpProxy({url:"TownCodeInfo"}),
请求成功了吗?数据确实发送到前台来了吗?

另外 store.load(); 这句最好放在grid渲染后
不过放到前面貌似也没什么影响
[/Quote]

请求成功了,但是数据就是不显示
kc8886 2010-08-31
  • 打赏
  • 举报
回复
proxy:new Ext.data.HttpProxy({url:"TownCodeInfo"}),
请求成功了吗?数据确实发送到前台来了吗?

另外 store.load(); 这句最好放在grid渲染后
不过放到前面貌似也没什么影响

52,797

社区成员

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

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