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;	
	}

暂时只想得到这么多,以后慢慢补

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值