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;
}
轉載于:https://blog.51cto.com/kefly/1584415
總結
以上是生活随笔為你收集整理的Extjs 4.2 +Struts2 实现数据动态加载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转:3d max 2013 安装教程,凭
- 下一篇: opencms的主工作区文件研究