extjs里的grid怎么在页面显示数据,后台是ssh
jsp页面//显示用户信息Ext.QuickTips.init();varcm=newExt.grid.ColumnModel([{header:'用户账号',dataI...
jsp页面
//显示用户信息
Ext.QuickTips.init();
var cm = new Ext.grid.ColumnModel([
{header: '用户账号', dataIndex: 'id'},
{header: '用户姓名', dataIndex: 'username'},
{header: '用户密码', dataIndex: 'password'},
{header: '年龄', dataIndex: 'age'},
{header: '生日', dataIndex: 'birthday'},
{header: '地址', dataIndex: 'address'},
{header: 'resume', dataIndex: 'resume'}
]);
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'ListUsersAction'}),
reader: new Ext.data.JsonReader({
totalProperty: 'totalCount',
id:'id',
root:'list'
}, [
{id:'id',name: 'id',mapping:'id'},
{name: 'name',mapping:'name'},
{name: 'password',mapping:'password'},
{name: 'age',mapping:'age'},
{name: 'birthday',mapping:'birthday'},
{name: 'address',mapping:'address'},
{name: 'resume',mapping:'resume'}
])
});
var grid = new Ext.grid.GridPanel({
renderTo:document.body,
autoHeight: true,
store: store,
width:800,
height:400,
loadMask:true,
autoShow:true,
columnLines:true,
header:true,
frame:true,
cm:cm,
bbar: new Ext.PagingToolbar({
pageSize: 5,
store: store,
displayInfo: true,
displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
emptyMsg: "没有记录"
})
});
store.load({params:{start:0,limit:20}});
grid.render();
下面是后台的action:
package ssh.cn.com.action.users;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import ssh.cn.com.service.UsersService;
@SuppressWarnings("serial")
public class ListUsersAction extends ActionSupport {
private UsersService service;
public UsersService getService() {
return service;
}
public void setService(UsersService service) {
this.service = service;
}
@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
Map request = (Map) ActionContext.getContext().get("request");
request.put("list", service.findAll());
return SUCCESS;
}
} 展开
//显示用户信息
Ext.QuickTips.init();
var cm = new Ext.grid.ColumnModel([
{header: '用户账号', dataIndex: 'id'},
{header: '用户姓名', dataIndex: 'username'},
{header: '用户密码', dataIndex: 'password'},
{header: '年龄', dataIndex: 'age'},
{header: '生日', dataIndex: 'birthday'},
{header: '地址', dataIndex: 'address'},
{header: 'resume', dataIndex: 'resume'}
]);
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'ListUsersAction'}),
reader: new Ext.data.JsonReader({
totalProperty: 'totalCount',
id:'id',
root:'list'
}, [
{id:'id',name: 'id',mapping:'id'},
{name: 'name',mapping:'name'},
{name: 'password',mapping:'password'},
{name: 'age',mapping:'age'},
{name: 'birthday',mapping:'birthday'},
{name: 'address',mapping:'address'},
{name: 'resume',mapping:'resume'}
])
});
var grid = new Ext.grid.GridPanel({
renderTo:document.body,
autoHeight: true,
store: store,
width:800,
height:400,
loadMask:true,
autoShow:true,
columnLines:true,
header:true,
frame:true,
cm:cm,
bbar: new Ext.PagingToolbar({
pageSize: 5,
store: store,
displayInfo: true,
displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
emptyMsg: "没有记录"
})
});
store.load({params:{start:0,limit:20}});
grid.render();
下面是后台的action:
package ssh.cn.com.action.users;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import ssh.cn.com.service.UsersService;
@SuppressWarnings("serial")
public class ListUsersAction extends ActionSupport {
private UsersService service;
public UsersService getService() {
return service;
}
public void setService(UsersService service) {
this.service = service;
}
@SuppressWarnings("unchecked")
@Override
public String execute() throws Exception {
Map request = (Map) ActionContext.getContext().get("request");
request.put("list", service.findAll());
return SUCCESS;
}
} 展开
3个回答
展开全部
struts.xml:
<package name="default" namespace="/" extends="json-default">
<action name="listUsersAction" class="ListUsersAction">
<result type="json" />
</action>
</package>
需要用到jsonplugin.jar 这个包
详细的可以参照这个:
http://wenku.baidu.com/view/26d9a9f67c1cfad6195fa734.html
<package name="default" namespace="/" extends="json-default">
<action name="listUsersAction" class="ListUsersAction">
<result type="json" />
</action>
</package>
需要用到jsonplugin.jar 这个包
详细的可以参照这个:
http://wenku.baidu.com/view/26d9a9f67c1cfad6195fa734.html
追问
不行啊,按你说的配置了以后,直接就报错了。 我的QQ:158704426
详细聊。
追答
报的什么错?struts2+Extjs我是很早之前用过一点,后来觉得不太好,换成了dwr+Extjs了,dwr配合Extjs比较好用。
你好好看下我给你发的那个连接,你按那上面说的弄就差不多,前台这块你可以参照我这个回答:http://zhidao.baidu.com/question/175540962.html
总之,你前台索要的url,就是struts2配置的action,而这个action所返回的就是组织好的json
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
extjs与后台无关..
追问
你学过没有?懂的extjs与后台交互不?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-06
展开全部
详细可百度Hi中详谈
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询