EXTJS读取后台数据总是无法显视grid中

ycwsx 2008-12-31 05:26:17
我用asp写的json数据输出
<%
json = "{totalCount:100,topics:["
set rs=server.createobject("adodb.recordset")
sql="select id,dept,code,name,sex from employee"
rs.open sql,conn,1,1
rscount=rs.recordcount
i=1
do while not rs.eof
json =json+ "{id:'"& i &"',dept:'"& trim(rs("dept")) &"',code:'"& trim(rs("code")) &"',name:'"& trim(rs("name")) &"',sex:'"& trim(rs("sex")) &"'}"
'json =json+ "{'id':"& i &",'dept':'"& trim(rs("dept")) &"','code':'"& trim(rs("code")) &"','name':'"& trim(rs("name")) &"','sex':'"& trim(rs("sex")) &"'}"
rs.movenext
i=i+1
if i<rscount+1 then
json =json+","
end if
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
json =json+ "]}"
Response.Write( json )
%>
...全文
230 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luohuanquan 2009-01-21
  • 打赏
  • 举报
回复
Ext.data.Store 应该改为Ext.data.JsonStore 因为你返回的是json数据
ycwsx 2009-01-02
  • 打赏
  • 举报
回复
<script type="text/javascript">
Ext.onReady(function(){
var ds = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({url:'json.asp'}),
reader: new Ext.data.JsonReader({
root: 'topics',
totalProperty: 'totalCount',
id: 'id'
},['id','dept','code','name','sex'])
});

var colModel = new Ext.grid.ColumnModel([
{header:'编号',width:50,sortable:true,dataIndex:'id'},
{header:'部门', width:100,sortable:true,dataIndex:'dept'},
{header:'工号',width:100,sortable:true,dataIndex:'code'},
{header:'姓名',width:100,sortable:true,dataIndex:'name'},
{header:'性别',width:100,sortable:true,dataIndex:'sex'}

]);
var tb = new Ext.Toolbar('north-div');//创建一个工具条

tb.add({
text: '添加',
handler: addItem
},{
text: '编辑',
handler: editItem
},{
text: '删除',
handler: delItem
});

var grid = new Ext.grid.GridPanel({
border:false,
region:'center',
loadMask: true,
el:'center',
title:'条目列表',
store: ds,
cm: colModel,

autoScroll: true,
bbar: new Ext.PagingToolbar({
pageSize: 30,
store: ds,
displayInfo: true,
displayMsg: '第{0} 到 {1} 条数据 共{2}条',
emptyMsg: "没有数据"
})
});
var viewport = new Ext.Viewport({
layout:'border',
items:[{
border:false,
region:'north',
contentEl:'north-div',
tbar:tb,
height:26
},
grid
]}
);
ds.load({params:{start:0, limit:30, forumId: 4}});
function addItem(action) {
var id = 0;
if (action=='edit') {
var id = getId(grid);
if (!id) {
Ext.Msg.alert('出错啦','你还没有选择要操作的记录!');
return;
}
}
parent.openWindow('40005101','添加资料','index.asp?action=add',300,240);
}
function editItem() {
addItem('edit');
}
function delItem() {
var ids = getIds(grid);
if (ids) {
Ext.Msg.confirm('确认', '真的要删除吗?', function(btn){
if (btn == 'yes'){
Ext.Ajax.request({
url: 'index.asp?action=delete&ids='+ids,
success: function(result){
ds.reload();
}
});
}
});

} else {
Ext.Msg.alert('出错啦','你还没有选择要操作的记录!');
}
}
loadend();
});
</script>
<div id="north-div"></div>
<div id="center"></div>
午夜咖啡男 2008-12-31
  • 打赏
  • 举报
回复
请帖完整的 Ext.gird.EditorGridPanel的实例化代码,以及Ext.onReady中的内容
ycwsx 2008-12-31
  • 打赏
  • 举报
回复
前台中的EXTJS如下:
var ds = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({url:'json.asp'}),
reader: new Ext.data.JsonReader({
root: 'topics',
totalProperty: 'totalCount',
id: 'id'
},['id','dept','code','name','sex'])
});

var colModel = new Ext.grid.ColumnModel([
{header:'编号',width:50,sortable:true,dataIndex:'id'},
{header:'部门', width:100,sortable:true,dataIndex:'dept'},
{header:'工号',width:100,sortable:true,dataIndex:'code'},
{header:'姓名',width:100,sortable:true,dataIndex:'name'},
{header:'性别',width:100,sortable:true,dataIndex:'sex'}

]);



搞了好久没有数据显视

52,797

社区成员

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

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