Extjs 4.2 +Struts2 实现数据动态加载
//自定义一个的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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。