ajax异步加载TreeGrid数据,使用empty()清空原始数据

$(document).ready(function(){
	var treeGrid;
	//初始化TreeGrid数据
	getTreeGridDate();
});
function getTreeGridDate(idMerchant){
	if(!idMerchant){
		idMerchant=-1;
	}
	$.ajax(
		type:"get",
		url:basePath + “xxx/xxx/xx.do?adt=”+new Date().getTime(),
		data:{"idMerchant":idMerchant},
		dataType:"json",
		success:function(data){//后端返回json格式的字符串
			if(data){
				$("div1").empty();//清空原来的TreeGrid
				var  dataTreeGridSource = eval(data);//转成数组对象
			var config = {
		            id: "tg1",
		            width: "800",
		            renderTo: "div1",
		            headerAlign: "left",
		            headerHeight: "30",
		            dataAlign: "left",
		            indentation: "20",
		            folderOpenIcon: "images/folderOpen.gif",
		            folderCloseIcon: "images/folderClose.gif",
		            defaultLeafIcon: "images/defaultLeaf.gif",
		            hoverRowBackground: "false",
		            folderColumnIndex: "1",
		            itemClick: "itemClickEvent",
		            columns: [
		            			{ headerText: "", headerAlign: "center", dataAlign: "center", width: "20", handler: "customCheckBox" },
						{ headerText: "名称", dataField: "name", headerAlign: "center", handler: "customOrgName" },
						{ headerText: "拼音码", dataField: "code", headerAlign: "center", dataAlign: "center", width: "100" },
						{ headerText: "负责人", dataField: "assignee", headerAlign: "center", dataAlign: "center", width: "100" }
					],
		            data:dataTreeGridSource 
		        	};
		        
		       //创建一个组件对象
	        	treeGrid = new TreeGrid(config);
	       		 treeGrid.show(); 
			}else if(!data){
				$("div1").empty();
				$("div1").append("<table id=\"tg1\" ................暂无数据....");
			}
		},
		error:function(){
			alert("查询异常,请稍后再试或联系管理员。。。");
		}

	});
}

如果是修改或者展示已经勾选的,则需要先查出已经勾选过的id数组,然后再在customCheckBox()方法中进行判断处理:

var idArray = ...;//从后台查询得到

function customCheckBox(row, col) {

for(var  i  in  idArray){

if(idArray[i] == row.idOper){

return "<input type='checkbox'  name='idCategory'  value="+row.idOper+" check='checked'>";

}

}
            return "<input type='checkbox'  name='idCategory'  value="+row.idOper+">";
}


此外empty()函数在做清除原来数据方面有很大作用。如级联下拉的清除也需要如此。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值