ajax异步加载TreeGrid数据,使用empty()清空原始数据
2015-12-20 00:44
447 查看
$(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()函数在做清除原来数据方面有很大作用。如级联下拉的清除也需要如此。
相关文章推荐
- SpringMVC中使用Interceptor拦截器
- 使用jQuery Deferred对象实现Promise
- 关于绝对路径和相对路径
- LeetCode 20:Valid Parentheses
- 关于微信开发与微信支付更新
- 看了thinking in java 的initialize and cleanup 的一点总结
- leetcode刷题日记——Binary Tree Inorder Traversal
- 读书笔记——《图解TCP/IP》(3/4)
- Sublime Text 3 快捷键总结
- 23种设计模式之Java实现
- maven 常用命令
- (转)Oracle查询性能优化
- Marklogic学习 由浅入深(5)-- Marklogic概念解析
- cocos2d-x Programmers Guide v3.3 译本和阅读笔记(第6章UI)
- Android中实用小技巧集锦
- 看“斯坦福监狱实验”有感
- maven 生命周期
- ASP.NET MVC中,怎么使用jquery/ajaxForm上传文件
- iOS开发:多个按钮点击滑动效果
- 安卓设置默认应用功能失效,设置后仍然总是反复提示选择默认使用的应用