easyui與框架整合需要注意的問題

1.與struts2整合時,如果通過form('submit')方式提交,需要設置@Action(name="",type="json",params={"contentType","text/html"}

2.與struts整合時,如何傳datagrid的easyui可識別的json,因爲用struts2的json方式,easyui是不識別的,這時候有兩種做法,一是直接返回jsonobject到前臺.這樣是可以顯示出來,但會有問題.還有一種辦法是,用servlet方式返回json.代碼如下:

@Action("/listCleanToolData")
	public String listData(){
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/html;charset=UTF-8");
			JSONObject jsonobj = new JSONObject();
			PrintWriter out = response.getWriter();
			Map<String,Object> map = new HashMap<String,Object>();
			//如果有自定義排序字段,在該註釋下面寫
			
			//自定義排序字段設置結束
			map = ControlUtil.getParams(ServletActionContext.getRequest(),map);
			PageInfo<CleanTool> pageInfo = ControlUtil.getPageinfo(ServletActionContext.getRequest());
			pageInfo.setResult(cleanToolService.findListByMap(null, map, pageInfo));
			pageInfo.setCount(cleanToolService.countByPage(map));
			JSONArray rows = null;
			long total = 0L;
			if(null != pageInfo && null != pageInfo.getResult() && pageInfo.getResult().size() > 0){
				rows = JSONArray.fromObject(pageInfo.getResult(),JsonFilter.getFilter());
				total = pageInfo.getCount();
			} else {
				rows = JSONArray.fromObject(new ArrayList<CleanTool>(),JsonFilter.getFilter());
				total = 0;
			}
			Map<String,Object> json = new HashMap<String, Object>();
			json.put("rows", rows);
			json.put("total", total);
			jsonobj = JSONObject.fromObject(json);// 格式化result一定要是JSONObject
			out.print(jsonobj);
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
以上代碼僅作參考,只需瞭解對你有用的代碼即可.


3.easyui的表格數據,如果最後一欄目爲操作選項, 放的是各種圖標(圖標綁定事件).如刪除按鈕,上面的toolbar上,是多刪除按鈕,而每一行數據後面有單個刪除按鈕,這時候,js一定要寫得通用纔好,不然有時候會提示你選擇一行數據,不知道大家有沒有碰到過,反正我看別人是碰到過的.代碼如下


function del(ids){
	if(ids=="" || ids == undefined){
		var rows = $("#listTable").datagrid("getSelections");
		if(rows != null && rows != "" && rows.length >= 1){
			$.each(rows,function(k){
				if(ids != "") ids += ",";
				ids += "\'" + rows[k].id + "\'";
			});
		} else {
			msg("提示","請至少選擇一條記錄!");
			return;
		}
	} else {
		ids = "\'" + ids + "\'";
	}
	window.top.$.messager.confirm('請確認','您確定要刪除選中的記錄嗎?',function(r){   
	    if (r){
			$.ajax({
				url:"<c:url value='/vote/deleteVote.do'/>",
				type:"post",
				data:"ids=" + ids,
				dataType:"json",
				async:false,
				success:function(result){
					if(!result) return;
					var re = result.msg;
					msg("提示ʾ",re);
					$("#listTable").datagrid("reload");
				}
			});
	    }   
	});  
}


4.easyui通用的window全局模態代碼.

//在最頂層彈出窗口
	function my_window(winid,url,title,width,height){
		//winid是用來關閉該模態窗口的標識.
		if(!url) return;
		if(!width) width = 300;
		if(!height) height = 300;
		var html = "<div id=\"window_" + winid + "\" style=\"padding:0px;\">"
			+"<iframe src='" + url + "' frameborder='0' id='childFrame' name='childFrame' marginheight='0' style='width:100%;height:100%;' marginwidth='0' scrolling='auto' width='100%' height='100%'></iframe>"
			+"</div>";
		var win = window.top.$(html).appendTo(window.top.document.body);
			win.window({
				//標題
				title : title,
				//寬度
				width : width,
				//是否模態
				modal : true,
				//是否顯示陰影
				shadow : false,
				//
				closed : true,
				//是否顯示右上角的關閉按鈕
//				closable : false,
				//是否能最小化
				minimizable : false,
				//是否可摺疊
				collapsible : false,
				//是否能最大化
//				maximizable : false,
				//高度
				height : height,
				//是否可拖動
				draggable : true,
				//浮動量
				zIndex : 999,
				//對於主父窗口如何停留的定義,true 該窗口停留在父窗口上, false 該窗口始終顯示在最頂層,默認爲false(這個定義等同於javax.swing裏的dialog)
				inline : true,
				//關閉事件執行詳細
				onClose : function() {
					//頂層模態需在頂層關閉,否則無效
					window.setTimeout(function() {
						window.top.$(win).window('destroy', false);
					}, 0);
				}
			});
		win.window('open');
		return win;	
	}

暫時只想得到這麼多,以後慢慢補
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章