easyui-datagrid向后台传送其它的参数

8 篇文章 0 订阅
9 篇文章 0 订阅

一般情况下不会用到,今天遇到了,查了一些资料,下面把实现方法写下来

//easyui带参数向后台发送请求
		$('#grid').datagrid({  	
			  queryParams: {  		
			    nodeID: nodeId  		
			  }  
			});  


下面是我程序中的功能代码,实现的主要功能是,当点击easyui-tree中的一个节点,则与该节点关联的文件,自动勾选上


在easyui-datagrid在加载数据时,第一列为复选框,若没有,则用到下面代码添加,我是业务需要所以添加,若只是传参则有没有都可以

需求是在加载后,与目录关联的文件的复选框要处于选中状态,这里目录如何实现暂时不写,有空写。

页面初始化时加载数据

$(function(){
	//$("body").css({visibility:"visible"});
	//$('.buttonStyle').hover(function(){$(this).removeClass('buttonStyle').addClass('overButtonStyle')},function(){$(this).removeClass('overButtonStyle').addClass('buttonStyle')})
	$('#grid').datagrid({
		fit : true,
		border : false,
		rownumbers : true,
		animate: true,
		striped : true,
		pageList : [ 10, 20, 50 ],
		pagination : true,
		url : "${pageContext.request.contextPath}/document/listAll",
		columns : columns,
		loadMsg:'数据加载中...',
		onLoadSuccess: function (data) {
	            if (data.total == 0) {
	            	$("#centerNews").css("display","none");
	            	$("#showNews").css("display","block")
	            }
	            else {
	            	//对应相应目录,使之勾选上
	            	$.each(data.rows, function(index, item){
	            		if(item.checked){
	            			$('#grid').datagrid('checkRow', index);
	            		}
	            	});
	            	
	            	$("#showNews").css("display","none")
	            	$("#centerNews").css("display","block");
	            }
	        },
	});
	setInterval(checkChooseNode,2000);
});
传递参数到后台代码,我用的是setInterval方法,因为这个页面是用frame做的是个子页面,所以用这个方法定时刷新,跟踪父页面的相关变量的变化

function checkChooseNode(){
	//循环获取父页面中的数据
	var path = $('#path', window.parent.document);
	$("#parents").html(path.html());//与父页面节点的路径同步
	var map = parent.window.getSelectedNodeData();//调用父页面的方法,获取当前选中的节点
	nodeName = map['nodeName'];
	nodeId = map['nodeId'];
	if(notAllowRepeatSubmit != nodeId){
		//带参数向后台发送请求
		$('#grid').datagrid({  	
			  queryParams: {  		
			    nodeID: nodeId  		
			  }  
			});  
	}
	notAllowRepeatSubmit = nodeId;//notAllowRepeatSubmit 这个参数定义的是全局变量,用于防止重复向后台发送请求
}

前台以上就写完了,下面是后台代码

controller层

@RequestMapping(value = "/listAll", method = RequestMethod.POST)
	public ResponseEntity<?> list(JSPPageVo vo) {
		try {
			Map<String, Object> json = documentService.findDocListData(vo);
			return new ResponseEntity<Map<String, Object>>(json, HttpStatus.OK);
		} catch (Exception e) {
			logger.error("资料管理listAll异常:", e);
			throw new RestException(messageSourceHelper.getMessage(e.getMessage()));
		}
	}
JSPPageVo类用来接收参数

import java.io.Serializable;
/**
 * 用于封装JSP datagrid查询/分页查询参数
 */
public class JSPPageVo  implements Serializable{

	private static final long serialVersionUID = 1559887336950341618L;
	
	private String key;
	private String key2;
	private String key3;
	private String nodeID;
	
	
	public String getKey2() {
		return key2;
	}
	public void setKey2(String key2) {
		this.key2 = key2;
	}
	public String getKey3() {
		return key3;
	}
	public void setKey3(String key3) {
		this.key3 = key3;
	}
	private String page;
	private String rows;
	private String startTime;
	private String endTime;
	private String isDeleted;
	
	public String getIsDeleted() {
		return isDeleted;
	}
	public void setIsDeleted(String isDeleted) {
		this.isDeleted = isDeleted;
	}
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public String getRows() {
		return rows;
	}
	public void setRows(String rows) {
		this.rows = rows;
	}
	public String getNodeID() {
		return nodeID;
	}
	public void setNodeID(String nodeID) {
		this.nodeID = nodeID;
	}
	
	

}
service层

@Override
	public Map<String, Object> findDocListData(JSPPageVo vo) {
		List<DocumentVo> dlist = new ArrayList<DocumentVo>();
		String nodeID = vo.getNodeID();
		List<DocumentFolderLink> dfl = documentFolderLinkDao.findListByFolderId(nodeID);
		
		PageRequest pager = buildPageRequest(Integer.parseInt(vo.getPage()), Integer.parseInt(vo.getRows()), "create_time", "DESC");
		Page<Document> result = documentDao.searchByIsDeletedAndPage(pager);
		List<Document> list = result.getContent();
		Map<String, Object> json = new HashMap<String, Object>();
		if(dfl.size() >0){
			//遍历list,关联勾选
			for(Document doc: list){
				int i = 0;//给每条记录做标签
				for(DocumentFolderLink dflk: dfl){
					if(StringUtils.equals(dflk.getDocument_id(), doc.getId())){
						//说明此条数据要加item状态
						DocumentVo dva = documentToVoADD(doc);
						dlist.add(dva); 
						i=1;
					}
				}
				if(i == 0){
					DocumentVo dv = documentToVo(doc);
					dlist.add(dv);
				}
			}
			json.put("rows", dlist);
		}else{
			json.put("rows", list);
		}
		long count = result.getTotalElements();
		json.put("total", count);

		return json;
	}
documentToVoADD方法,添加字段checked的值为true

private DocumentVo documentToVoADD(Document doc) {
		DocumentVo dvo = new DocumentVo();
		dvo.setCreate_time(doc.getCreate_time());
		dvo.setDocument_agree_count(doc.getDocument_disagree_count());
		dvo.setDocument_disagree_count(doc.getDocument_disagree_count());
		dvo.setDocument_download_count(doc.getDocument_download_count());
		dvo.setDocument_download_path(doc.getDocument_local_path());
		dvo.setDocument_icon(doc.getDocument_icon());
		dvo.setDocument_is_new(doc.getDocument_is_new());
		dvo.setDocument_keywords(doc.getDocument_keywords());
		dvo.setDocument_local_path(doc.getDocument_local_path());
		dvo.setDocument_md5_sum(doc.getDocument_md5_sum());
		dvo.setDocument_name(doc.getDocument_name());
		dvo.setDocument_page_count(doc.getDocument_page_count());
		dvo.setDocument_size(doc.getDocument_size());
		dvo.setDocument_summary(doc.getDocument_summary());
		dvo.setDocument_title(doc.getDocument_title());
		dvo.setDocument_type(doc.getDocument_type());
		dvo.setDocument_upload_cdn(doc.getDocument_upload_cdn());
		dvo.setDocument_version(doc.getDocument_version());
		dvo.setId(doc.getId());
		dvo.setIs_deleted(doc.getIs_deleted());
		dvo.setChecked(true);
		dvo.setUpdate_time(doc.getUpdate_time());
		return dvo;
	}
documentToVo方法,正常值转换不对checded设置

private DocumentVo documentToVo(Document doc) {
		DocumentVo dvo = new DocumentVo();
		dvo.setCreate_time(doc.getCreate_time());
		dvo.setDocument_agree_count(doc.getDocument_disagree_count());
		dvo.setDocument_disagree_count(doc.getDocument_disagree_count());
		dvo.setDocument_download_count(doc.getDocument_download_count());
		dvo.setDocument_download_path(doc.getDocument_local_path());
		dvo.setDocument_icon(doc.getDocument_icon());
		dvo.setDocument_is_new(doc.getDocument_is_new());
		dvo.setDocument_keywords(doc.getDocument_keywords());
		dvo.setDocument_local_path(doc.getDocument_local_path());
		dvo.setDocument_md5_sum(doc.getDocument_md5_sum());
		dvo.setDocument_name(doc.getDocument_name());
		dvo.setDocument_page_count(doc.getDocument_page_count());
		dvo.setDocument_size(doc.getDocument_size());
		dvo.setDocument_summary(doc.getDocument_summary());
		dvo.setDocument_title(doc.getDocument_title());
		dvo.setDocument_type(doc.getDocument_type());
		dvo.setDocument_upload_cdn(doc.getDocument_upload_cdn());
		dvo.setDocument_version(doc.getDocument_version());
		dvo.setId(doc.getId());
		dvo.setIs_deleted(doc.getIs_deleted());
		dvo.setUpdate_time(doc.getUpdate_time());
		return dvo;
	}
DocumentVo类比Document实体类多一个checked字段,其它都一样,用的是JPA查询,dao层就不写了





参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

wei_lanSe

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值