extjs grid从struts2中取值问题
js页面代码如下:Ext.onReady(function(){Ext.BLANK_IMAGE_URL='extJs/resources/images/default/s...
js页面代码如下:
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = 'extJs/resources/images/default/s.gif';
Ext.form.Field.prototype.msgTarget = 'test';
Ext.QuickTips.init();
var PageSize = 15;
var js = new Ext.data.JsonStore({
url : '/demo/test/userfindList.action',
root : "userList",
fields : [{name : 'user.id',mapping : 'id'},
{name : 'user.name',mapping : 'name'},
{name : 'user.sex',mapping:'sex'},
{name : 'user.age',mapping:'age'},
{name : 'user.height',mapping:'height'},
{name : 'user.post',mapping:'post'}] });
js.load();
var grid = new Ext.grid.GridPanel({
store : js,
columns: [
{id:'user.id',header: '序号', width: 25, sortable: true, dataIndex: 'id'},
{header: '姓名', width: 75, sortable: true, dataIndex: 'name'},
{header: '性别', width: 75, sortable: true, dataIndex: 'sex'},
{header: '年龄', width: 75, sortable: true, dataIndex: 'age'},
{header: '身高', width: 85, sortable: true, dataIndex: 'height'},
{header: '职位', width: 85, sortable: true, dataIndex: 'post'}
],
stripeRows : true,
loadMask : {
msg : '正在加载数据,请稍侯……'
},
stripeRows: true,
autoExpandColumn: 'user.id',
height: 350,
width: 600,
title:'职工信息列表',
stateful: true,
stateId: 'grid'
});
grid.render('grid-example');
});
Action中代码如下:
package cn.com.test.demo.actions;
import java.util.List;
import org.springframework.stereotype.Controller;
import cn.com.newsky.demo.hbm.User;
import com.opensymphony.xwork2.ActionSupport;
/*BaseAction*/
@Controller("userAction")
public class UserAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private List<User> userList;
public String findList(){
this.getUsers();
System.out.println("长度:::"+userList.size());
return null;
}
public List<User> getUserList() {
return userList;
}
public void setUserList(List<User> userList) {
this.userList = userList;
}
public void getUsers(){
for(int i=0;i<10;i++){
User users = new User();
users.setAge("age"+i);
users.setName("name"+i);
users.setHeight("height"+i);
users.setSex("sex"+i);
users.setPost("post"+i);
users.setId(""+i);
userList.add(users);
}
}
}
谢谢各位高手了,急着用。
将findList中加入了代码
userList = getUsers();
JSONArray jsonArray = JSONArray.fromObject(userList);
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/json;charset=UTF-8");
response.getWriter().write("{userList:"+jsonArray+"}");
怎么还是不行啊,还是取不出来数据啊。 展开
Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = 'extJs/resources/images/default/s.gif';
Ext.form.Field.prototype.msgTarget = 'test';
Ext.QuickTips.init();
var PageSize = 15;
var js = new Ext.data.JsonStore({
url : '/demo/test/userfindList.action',
root : "userList",
fields : [{name : 'user.id',mapping : 'id'},
{name : 'user.name',mapping : 'name'},
{name : 'user.sex',mapping:'sex'},
{name : 'user.age',mapping:'age'},
{name : 'user.height',mapping:'height'},
{name : 'user.post',mapping:'post'}] });
js.load();
var grid = new Ext.grid.GridPanel({
store : js,
columns: [
{id:'user.id',header: '序号', width: 25, sortable: true, dataIndex: 'id'},
{header: '姓名', width: 75, sortable: true, dataIndex: 'name'},
{header: '性别', width: 75, sortable: true, dataIndex: 'sex'},
{header: '年龄', width: 75, sortable: true, dataIndex: 'age'},
{header: '身高', width: 85, sortable: true, dataIndex: 'height'},
{header: '职位', width: 85, sortable: true, dataIndex: 'post'}
],
stripeRows : true,
loadMask : {
msg : '正在加载数据,请稍侯……'
},
stripeRows: true,
autoExpandColumn: 'user.id',
height: 350,
width: 600,
title:'职工信息列表',
stateful: true,
stateId: 'grid'
});
grid.render('grid-example');
});
Action中代码如下:
package cn.com.test.demo.actions;
import java.util.List;
import org.springframework.stereotype.Controller;
import cn.com.newsky.demo.hbm.User;
import com.opensymphony.xwork2.ActionSupport;
/*BaseAction*/
@Controller("userAction")
public class UserAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private List<User> userList;
public String findList(){
this.getUsers();
System.out.println("长度:::"+userList.size());
return null;
}
public List<User> getUserList() {
return userList;
}
public void setUserList(List<User> userList) {
this.userList = userList;
}
public void getUsers(){
for(int i=0;i<10;i++){
User users = new User();
users.setAge("age"+i);
users.setName("name"+i);
users.setHeight("height"+i);
users.setSex("sex"+i);
users.setPost("post"+i);
users.setId(""+i);
userList.add(users);
}
}
}
谢谢各位高手了,急着用。
将findList中加入了代码
userList = getUsers();
JSONArray jsonArray = JSONArray.fromObject(userList);
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/json;charset=UTF-8");
response.getWriter().write("{userList:"+jsonArray+"}");
怎么还是不行啊,还是取不出来数据啊。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询