您的位置:首页 > 编程语言 > Java开发

Extjs 4.2 +Struts2 实现数据动态加载

2014-11-29 11:48 435 查看
//自定义一个的js
function commodityQuery() {
Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
// Set up a model to use in our Store
Ext.define('Commodity', {
extend: 'Ext.data.Model',
fields: [
{name: 'commodityId', type: 'int'},
{name: 'commodityName', type: 'string'},
{name: 'price', type: 'float'},
{name: 'agio', type: 'float'}
]
});
var store = Ext.create('Ext.data.Store', {
model: 'Commodity',
proxy: {
type: 'ajax',
url : 'commodityQuery',
successProperty:'success',
reader: {
type: 'json',
root: 'results'
}
},
autoLoad: {start:0,limit:4}
});
var gridPanel = Ext.create('Ext.grid.Panel', {
width : 586,
height : 375,
store : store,
columns : [ {
text : "商品编号",
dataIndex : "commodityId",
sortable : true
}, {
text : "商品名称",
dataIndex : "commodityName",
sortable : true
}, {
text : "商品价格",
dataIndex : "price",
sortable : true,
autoWidth : 50
}, {
text : "商品折扣",
dataIndex : "agio",
sortable : true
} ],
forceFit : true,
bbar : [ Ext.create("Ext.toolbar.Paging", {
store : store,
displayInfo : true,
displayMsg : "显示 {0} - {1} 条,共计 {2} 条",
emptyMsg : "没有任何记录",
width : "100%"

}) ]

});
var commodityQueryWindow = Ext.create("Ext.window.Window", {
width : 600,
height : 400,
title : "商品信息查询",
resizable : false,
modal : true,
items : gridPanel
});
commodityQueryWindow.show();

}
**********************
Struts.xml 中的配置
//method 可以写成DMI方式
<action name="commodityQuery" class="com.rjxy.action.CommodityQueryAction" method="getCommodity" >
<result type="json">
<param name="root">responseJson</param>
</result>
</action>
**********************
CommodityQueryAction中的变量及方法
private String msg;
private List<Commodity> list;
private Integer totalCount;
private Map responseJson;
private SaleDaoImpl dao;
private Integer start;
private Integer limit;
/**
* Query Commodity list.
*/
public String getCommodity(){
Map<String, Object> map = new HashMap<String, Object>();
try{
conn = GetConnection.getConn();//jdbc连接,网友可以用hibernate
dao = new SaleDaoImpl();
list = dao.queryAllOrder();
if(list != null){
this.setTotalCount(list.size());
map.put("results", list);
map.put("totalCount", totalCount);
this.setResponseJson(map);
}
return SUCCESS;
}catch(Exception e){
e.printStackTrace();
return ERROR;
}

本文出自 “学习” 博客,请务必保留此出处http://kefly.blog.51cto.com/1109349/1584415
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: