关于easyui的tree的异步加载处理

1、前端jsp


<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<script type="text/javascript">
	$(function() {
//初始化,首次加载
		$('#goodsTree').tree({
			url:'${pageContext.request.contextPath}/admin/goodsTypeController/tree.do?id=NULL',
		    parentField : 'pid',
			lines : true,
	        onClick: function (node) {
	            clickTree(node);
	        },
	        onBeforeExpand:function(row){
				//处理tree的显示
				//动态设置展开查询的url  
			        var url = '${pageContext.request.contextPath}/admin/goodsTypeController/tree.do'; 
			        $("#goodsTree").tree("options").url = url;  
			        return true; 
			}
		});
//加载商品信息的datagrid,初始化
		$('#goods_datagrid').datagrid({
			//url : '${pageContext.request.contextPath}/admin/goodsController/datagrid.do?typeId=abc',
							fit : true,
							rownumbers : true,
							fitColumns : true,
							showFooter : true,
							border : false,
							pagination : true,
							idField : 'id',
							pageSize : 10,
							pageList : [10],
							sortName : 'name',
							sortOrder : 'asc',
							checkOnSelect : true,
							selectOnCheck : true,
							nowrap : false,
							frozenColumns : [ [ {
								field : 'id',
								title : '编号',
								width : 150,
								checkbox : true
							}, {
								field : 'typeId',
								title : '商品类别',width : 60,
								hidden : true
							}, {
								field : 'code',
								title : '商品编码',width : 100,
							}, {
								field : 'typeName',
								title : '类别名称',width : 200
							}, {
								field : 'name',
								title : '商品名称',width : 100
							}, {
								field : 'pinyin',
								title : '拼音',width : 80,hidden : true
							}, {
								field : 'shortname',
								title : '商品简称',width : 60,hidden : true
							}, {
								field : 'barcode',
								title : '条形码',width : 80,hidden : true
							}, {
								field : 'unit',
								title : '单位',width : 40
							}, {
								field : 'format',
								title : '规格',width : 80,hidden : true
							}, {
								field : 'nature',
								title : '商品性质',width : 80,hidden : true
							}, {
								field : 'pp',
								title : '商品品牌',width : 80
							}, {
								field : 'gys',
								title : '供应商',width : 80,hidden:true
							}, {
								field : 'cbj',
								title : '成本价',width : 80
							}, {
								field : 'buydate',
								title : '购买时间',width : 80,
								hidden : true
							}, {
								field : 'remark',
								title : '备注',width : 80,
								hidden : true
							} ] ],
							toolbar : [ {
								text : '全  部',
								iconCls : 'icon-relo',
								handler : function() {
									clickTree(null);
								}
							} ]
						});
	});
	function clickTree(node) {
		var urlstr = '';
		if(node.id==null){
			urlstr = '${pageContext.request.contextPath}/admin/goodsController/datagrid.do';
		}else{
			urlstr = '${pageContext.request.contextPath}/admin/goodsController/datagrid.do?typeId='+node.id;
		}
		$('#goods_datagrid').datagrid({ url: urlstr });
		$('#goods_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	}
</script>
<div class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;padding:5px;">
    <div  title="类别结构树" style="width:150px;padding:10px" data-options="region:'west',split:true">
    	<ul id="goodsTree"></ul>
    </div>
    <div data-options="region:'center',split:true">
        <div id="goods_datagrid" ></div>
    </div>
</div>


2、controller


@RequestMapping("/tree")
	@ResponseBody
	public List<GoodsTypePage> tree(@RequestParam("id") String id) {
		if(null==id || "".equals(id)){
			id="NULL";
		}
		return goodsTypeService.treeNode(id);
	}


3、service

@Override
	public List<GoodsTypePage> treeNode(String id) {
		List<GoodsTypePage> nl = new ArrayList<GoodsTypePage>();
		String hql = null;
		if(id.equals("NULL")){
			hql = "from GoodsType t where t.tgoodstype.id is NULL order by t.seq";
		}else{
			hql = "from GoodsType t where t.tgoodstype.id = '" +id+"' order by t.seq";
		}
		List<GoodsType> goodsTypeList = goodsTypeDao.find(hql);
		if (goodsTypeList != null && goodsTypeList.size() > 0) {
			for (GoodsType goodsType : goodsTypeList) {
				GoodsTypePage goodsTypePage = new GoodsTypePage();
				BeanUtils.copyProperties(goodsType, goodsTypePage);
				Map<String, Object> attributes = new HashMap<String, Object>();
				attributes.put("class", "type");
				goodsTypePage.setAttributes(attributes);
				goodsTypePage.setState("closed");
				nl.add(goodsTypePage);
			}
		}
		return nl;
	}

转载于:https://my.oschina.net/wfire/blog/167471

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值