ExtJS问题:已经从服务器端读到了json数据,但是在grid中不显示 30
//服务器端获得的数据转换为json格式json="{Employees:"+ExtHelper.getJsonFromList(employees)+"}";respo...
//服务器端获得的数据转换为json格式
json = "{Employees:"+ExtHelper.getJsonFromList(employees)+"}";
response.getWriter().write(json);
//转换之后的数据是(在火狐中查看的)
{Employees:{"items":[{"employee_birth":"1993年5月22日","employee_cid":"410344199305223603","employee_dept":"1","employee_id":1,"employee_image":"123","employee_indate":"03 15 2013 12:00AM","employee_name":"linxing","employee_outstate":0,"employee_pass":"1","employee_power":0,"employee_salary":"6000","employee_sex":"女","employee_tel":"15083527791","employee_title":"管理员"},{"employee_birth":"1992年11月24日","employee_cid":"111111111111111111","employee_dept":"1","employee_id":2,"employee_image":"123","employee_indate":"03 15 2013 12:00AM","employee_name":"kef","employee_outstate":0,"employee_pass":"111111","employee_power":0,"employee_salary":"6000","employee_sex":"女","employee_tel":"15083527791","employee_title":"教师"],"results":3}}
/*在客户端读取时*/
//创建员工信息列表的数据模型
Ext.regModel('Employees',{
fields: [
{name:'employee_id'},
{name:'employee_name'},
{name:'employee_cid'},
{name:'employee_sex'},
{name:'employee_salary'},
{name:'employee_dept'},
{name:'employee_title'},
{name:'employee_indate'},
{name:'employee_birth'},
{name:'employee_outstate'},
{name:'employee_pass'},
{name:'employee_image'},
{name:'employee_tel'}]
});
//定义员工信息的数据源对象以及选择代理
var employeeStore = Ext.create('Ext.data.Store',{
autoLoad:true,
model:'Employees',
proxy:{
type:'ajax',
url:'allEmployeesAction',
reader:{
type:'json',
implicitIncludes:true,
record:'items',
root:'Employees',
idProperty: 'employee_cid',
totalProperty:'results'
}
}
});
//创建工具栏组件
var toolbar = [
{text:'新员工入职',iconCls:'add'},
{text:'员工信息修改',iconCls:'plugin'},
{text:'员工离职',iconCls:'delete'}
];
alert(employeeStore);
alert(employeeStore.items);
//创建Grid表格组件
Ext.create('Ext.grid.Panel',{
tbar:toolbar,
store:employeeStore,
selModel:new Ext.selection.CheckboxModel(),
renderTo:'emlist',
columns:[
{text:'员工编号',width:60,dataIndex:'employee_id',sortable:true},
{text:'姓名',width:80,dataIndex:'employee_name',sortable:true},
{text:'身份证号码',width:100,dataIndex:'employee_cid',sortable:true},
{text:'性别',width:60,dataIndex:'employee_sex',sortable:true},
{text:'薪资',width:80,dataIndex:'employee_salary',sortable:true},
{text:'职位',width:60,dataIndex:'employee_title',sortable:true},
{text:'入职日期',width:80,dataIndex:'employee_indate',sortable:true},
{text:'生日',width:80,dataIndex:'employee_birth',sortable:true},
{text:'在职状态',width:80,dataIndex:'employee_outstate',sortable:true},
{text:'密码',width:80,dataIndex:'employee_pass',sortable:true},
{text:'头像',width:80,dataIndex:'employee_image',sortable:true}
]
});
显示结果:
不显示具体数据 展开
json = "{Employees:"+ExtHelper.getJsonFromList(employees)+"}";
response.getWriter().write(json);
//转换之后的数据是(在火狐中查看的)
{Employees:{"items":[{"employee_birth":"1993年5月22日","employee_cid":"410344199305223603","employee_dept":"1","employee_id":1,"employee_image":"123","employee_indate":"03 15 2013 12:00AM","employee_name":"linxing","employee_outstate":0,"employee_pass":"1","employee_power":0,"employee_salary":"6000","employee_sex":"女","employee_tel":"15083527791","employee_title":"管理员"},{"employee_birth":"1992年11月24日","employee_cid":"111111111111111111","employee_dept":"1","employee_id":2,"employee_image":"123","employee_indate":"03 15 2013 12:00AM","employee_name":"kef","employee_outstate":0,"employee_pass":"111111","employee_power":0,"employee_salary":"6000","employee_sex":"女","employee_tel":"15083527791","employee_title":"教师"],"results":3}}
/*在客户端读取时*/
//创建员工信息列表的数据模型
Ext.regModel('Employees',{
fields: [
{name:'employee_id'},
{name:'employee_name'},
{name:'employee_cid'},
{name:'employee_sex'},
{name:'employee_salary'},
{name:'employee_dept'},
{name:'employee_title'},
{name:'employee_indate'},
{name:'employee_birth'},
{name:'employee_outstate'},
{name:'employee_pass'},
{name:'employee_image'},
{name:'employee_tel'}]
});
//定义员工信息的数据源对象以及选择代理
var employeeStore = Ext.create('Ext.data.Store',{
autoLoad:true,
model:'Employees',
proxy:{
type:'ajax',
url:'allEmployeesAction',
reader:{
type:'json',
implicitIncludes:true,
record:'items',
root:'Employees',
idProperty: 'employee_cid',
totalProperty:'results'
}
}
});
//创建工具栏组件
var toolbar = [
{text:'新员工入职',iconCls:'add'},
{text:'员工信息修改',iconCls:'plugin'},
{text:'员工离职',iconCls:'delete'}
];
alert(employeeStore);
alert(employeeStore.items);
//创建Grid表格组件
Ext.create('Ext.grid.Panel',{
tbar:toolbar,
store:employeeStore,
selModel:new Ext.selection.CheckboxModel(),
renderTo:'emlist',
columns:[
{text:'员工编号',width:60,dataIndex:'employee_id',sortable:true},
{text:'姓名',width:80,dataIndex:'employee_name',sortable:true},
{text:'身份证号码',width:100,dataIndex:'employee_cid',sortable:true},
{text:'性别',width:60,dataIndex:'employee_sex',sortable:true},
{text:'薪资',width:80,dataIndex:'employee_salary',sortable:true},
{text:'职位',width:60,dataIndex:'employee_title',sortable:true},
{text:'入职日期',width:80,dataIndex:'employee_indate',sortable:true},
{text:'生日',width:80,dataIndex:'employee_birth',sortable:true},
{text:'在职状态',width:80,dataIndex:'employee_outstate',sortable:true},
{text:'密码',width:80,dataIndex:'employee_pass',sortable:true},
{text:'头像',width:80,dataIndex:'employee_image',sortable:true}
]
});
显示结果:
不显示具体数据 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询