extjs问题,gridpanel不能显示数据,但firebug显示已经收到了json格式数据了 20
{
name : 'userId',
type : 'string',
mapping : 'userId'
}, {
name : 'userName',
type : 'string',
mapping : 'userName'
}, {
name : 'sex',
type : 'string',
mapping : 'sex'
}, {
name : 'age',
type : 'string',
mapping : 'age'
}, {
name : 'entryDate',
type : 'string',
mapping : 'entryDate'
},{
name : 'birthPlace',
type : 'string',
mapping : 'birthPlace'
}, {
name : 'mingzu',
type : 'string',
mapping : 'mingzu'
}, {
name : 'subjectName',
type : 'string',
mapping : 'subjectName'
}, {
name : 'departmentName',
type : 'string',
mapping : 'departmentName'
}]);
var reader = new Ext.data.JsonReader({
totalProperty: 'results',
root: 'rows'
}, record);
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'UserBeanClServlet?type=query'},{method:'GET'}) ,
reader : reader,
remoteSort : true
});
store.setDefaultSort('userId', 'DESC');
store.load();
var grid = new Ext.grid.GridPanel({
id : 'fee_Grid',
name : 'fee_Grid',
autoHeight:true,
loadMask : '正在查找',
// cm:cmMol,
columns : [
{
header : '编号',
dataIndex : 'userId',
sortable :true,
width : 90
}, {
header : '姓名',
dataIndex : 'userName',
width : 90
}, {
header : '性别',
dataIndex : 'sex',
width : 90
}, {
header : '年龄',
dataIndex : 'age',
width : 90
}, {
header : '籍贯',
dataIndex : 'birthPlace',
width : 90
}, {
header : '入职时间',
dataIndex : 'entryDate',
width : 90
}, {
header : '名族',
dataIndex : 'mingzu',
width : 90
},{
header : '专业',
dataIndex : 'subjectName',
width : 90
},{
header : '部门',
dataIndex : 'departmentName',
width : 90
},{
id : 'operate',
header : '操作',
dataIndex : 'operate',
renderer : function(value, metadata, record, rowIndex, colIndex, store) {
var view = '<a href="#" onclick="view(' +rowIndex + ')">查看</a>';
var edit = '<a href="#" onclick="edit(' + rowIndex + ')">编辑</a>';
// var del = '<a href="#" onclick="del(' + rowIndex + ')">删除</a>';
return view+' '+edit;
}
}],
store : store,
});
grid.render("show2");
从服务器接收到的数据:
{results:'11',rows:[{userId:'138',userName:'www',sex:'男',age:'33',entryDate:'2000-01-01',birthPlace:'sc',mingzu:'han',subjectName:'计算机2',departmentName:'事业部'},{userId:'139',userName:'lili',sex:'男',age:'22',entryDate:'2000-02-01',birthPlace:'四川',mingzu:'汉',subjectName:'计算机2',departmentName:'事业部'},{userId:'140',userName:'lili',sex:'男',age:'22',entryDate:'2000-02-01',birthPlace:'四川',mingzu:'汉',subjectName:'计算机2',departmentName:'事业部'},{userId:'141',userName:'lili',sex:'男',age:'22',entryDate:'2000-02-01',birthPlace:'四川',mingzu:'汉',subjectName:'计算机2',departmentName:'事业部'}]} 展开
你最后的store:store后面多个,号
Ext.onReady(function() {
var record = Ext.data.Record.create([{
name : 'userId',
type : 'string',
mapping : 'userId'
}, {
name : 'userName',
type : 'string',
mapping : 'userName'
}, {
name : 'sex',
type : 'string',
mapping : 'sex'
}, {
name : 'age',
type : 'string',
mapping : 'age'
}, {
name : 'entryDate',
type : 'string',
mapping : 'entryDate'
}, {
name : 'birthPlace',
type : 'string',
mapping : 'birthPlace'
}, {
name : 'mingzu',
type : 'string',
mapping : 'mingzu'
}, {
name : 'subjectName',
type : 'string',
mapping : 'subjectName'
}, {
name : 'departmentName',
type : 'string',
mapping : 'departmentName'
}]);
var reader = new Ext.data.JsonReader({
totalProperty : 'results',
root : 'rows'
}, record);
var store = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : 'aaa.jsp'
}, {
method : 'GET'
}),
reader : reader,
remoteSort : true
});
store.setDefaultSort('userId', 'DESC');
store.load();
var grid = new Ext.grid.GridPanel({
id : 'fee_Grid',
name : 'fee_Grid',
autoWidth : true,
height : 300,
loadMask : '正在查找',
// cm:cmMol,
columns : [{
header : '编号',
dataIndex : 'userId',
sortable : true,
width : 90
}, {
header : '姓名',
dataIndex : 'userName',
width : 90
}, {
header : '性别',
dataIndex : 'sex',
width : 90
}, {
header : '年龄',
dataIndex : 'age',
width : 90
}, {
header : '籍贯',
dataIndex : 'birthPlace',
width : 90
}, {
header : '入职时间',
dataIndex : 'entryDate',
width : 90
}, {
header : '名族',
dataIndex : 'mingzu',
width : 90
}, {
header : '专业',
dataIndex : 'subjectName',
width : 90
}, {
header : '部门',
dataIndex : 'departmentName',
width : 90
}, {
id : 'operate',
header : '操作',
dataIndex : 'operate',
renderer : function(value, metadata,
record, rowIndex, colIndex, store) {
var view = '<a href="#" onclick="view('
+ rowIndex + ')">查看</a>';
var edit = '<a href="#" onclick="edit('
+ rowIndex + ')">编辑</a>';
// var del = '<a href="#" onclick="del('
// + rowIndex + ')">删除</a>';
return view + ' ' + edit;
}
}],
store : store
});
grid.render("show2");
});
我在我这运行了一下,修改了store多个,号的错误,并且修改了url的地址
aaa.jsp里的内容是:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-store"); //HTTP1.1
response.setHeader("Pragma", "no-cache"); //HTTP1.0
response.setDateHeader("Expires", 0); //prevents catching at proxy server
String json = "{results:'11',rows:[{userId:'138',userName:'www';,sex:'男',age:'33',entryDate:'2000-01-01',birthPlace:'sc',mingzu:'han',subjectName:'计算机2',departmentName:'事业部'},{userId:'139',userName:'lili',sex:'男',age:'22',entryDate:'2000-02-01',birthPlace:'四川',mingzu:'汉',subjectName:'计算机2',departmentName:'事业部'},{userId:'140',userName:'lili',sex:'男',age:'22',entryDate:'2000-02-01',birthPlace:'四川',mingzu:'汉',subjectName:'计算机2',departmentName:'事业部'},{userId:'141',userName:'lili',sex:'男',age:'22',entryDate:'2000-02-01',birthPlace:'四川',mingzu:'汉',subjectName:'计算机2',departmentName:'事业部'}]}";
response.getWriter().write(json);
%>
运行成功,见图片。