请问一下jquery easyui treegrid如何异步加载子节点

呵呵我来啦 2013-01-14 02:23:41
rt:点击自己点实现一层层加载,网上说只需要指定一个url,我使用的ajax 来做的,出发事件是onBeforeExpand,加载完子节点后,用的append方法,但是不对,没有形成一层一层的树形结构,而且再次伸缩展开会造成重复加载数据,太麻烦了,麻烦给点思路或者例子,感激不尽了~~
本人用的是asp.net mvc 有这样的例子就更好了,没有也没关系!网上查了很多还是没有明白。
...全文
11275 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
li_zhifu 2015-01-12
  • 打赏
  • 举报
回复
引用 21 楼 ygfmis 的回复:
treegrid异步加载后发现 getslections 不能获取到选中的子节点行 有人遇到过么?
treegrid方法中的idField必须指定,且必须是唯一的
Jwenzeng 2014-11-06
  • 打赏
  • 举报
回复
引用 21 楼 ygfmis 的回复:
treegrid异步加载后发现 getslections 不能获取到选中的子节点行 有人遇到过么?
我还卡着,请问你解决了吗,能分享下方法吗
ygfmis 2014-10-10
  • 打赏
  • 举报
回复
treegrid异步加载后发现 getslections 不能获取到选中的子节点行 有人遇到过么?
kk618172 2013-12-27
  • 打赏
  • 举报
回复
妹的,一个账号居然只允许连续回复3次,换个账号来: 实体类代码,get set方法就不贴了:

public class DictTreeGrid {
	private String id;
	private String dictCode;
	private String dictName;
	private String dictype;
	private String isUsed;
	private String state = "open";// open,closed
	private Object attributes;
	private List<DictTreeGrid> children;
	private String iconCls;
}
manager类里的getTreeGrid方法: #说明:URL 请求里没有传ID,是easyUI自动post过来的,第一次加载的时候,没有id传过来,就直接getRoot,就是获取一级目录,后面在点开某个节点的时候,easyUI又会自动的post数据,这个时候就会把当前行的id传过来

public List<DictTreeGrid> getTreeGrid(String id) {
		List<DictTreeGrid> treeList = new ArrayList<DictTreeGrid>();
		List<Dictionary> treeData = new ArrayList<Dictionary>();
		if (id == null) {
			treeData = baseDAO.getRoot();
		} else {
			treeData = baseDAO.findBy("dictype", id);
		}

		if (treeData != null && treeData.size() > 0) {
			for (Dictionary dict : treeData) {
				DictTreeGrid treeGrid = new DictTreeGrid();
				treeGrid.setId(dict.getId().toString());
				treeGrid.setDictCode(dict.getDictCode());
				treeGrid.setDictName(dict.getDictName());
				if (dict.getDictype() != null) {
					treeGrid.setDictype(dict.getDictype().toString());
				}
				if (dict.getIsUsed() != null) {
					treeGrid.setIsUsed(dict.getIsUsed().toString());
				}
                                //判断当前行还有子项没,有的话,就把state设置为closed
				if (hasChildren(dict.getId())) {
					treeGrid.setState("closed");
				}
				treeList.add(treeGrid);
			}
		}
		return treeList;
	}
Rlay_2 2013-12-27
  • 打赏
  • 举报
回复
url : path + '/dictionaryController/asyncTreeGrid.do' Controller层代码

@RequestMapping("/asyncTreeGrid")
	@ResponseBody
	public List<DictTreeGrid> asyncTreeGrid(HttpServletRequest request, HttpServletResponse response) {
		List<DictTreeGrid> treeList = new ArrayList<DictTreeGrid>();
		try {
			String id = request.getParameter("id");
			treeList = this.dictionartManager.getTreeGrid(id);
		} catch (Exception e) {
			logger.error("", e);
		}
		return treeList;
	}
Rlay_2 2013-12-27
  • 打赏
  • 举报
回复
数据库:
dictype关联id,呈现父子关系
Rlay_2 2013-12-27
  • 打赏
  • 举报
回复
我正好也遇到了,我做出来了,很简单的,贴代码,为过来人某点福利吧
夜猫人 2013-12-23
  • 打赏
  • 举报
回复
遇到相同蛋疼的问题
Mike_90 2013-08-20
  • 打赏
  • 举报
回复
我也遇到这个问题了,蛋疼啊,不知道怎么解决
yuhongpingimu 2013-04-20
  • 打赏
  • 举报
回复
hi,这个问题是怎么解决的呢? 我现在是只加载了第一级节点。 点开文件夹后面的都不显示。 但是数据已经回来了。
呵呵我来啦 2013-04-09
  • 打赏
  • 举报
回复
JavaScript code?1234onBeforeLoad:function(row,param){if(row)$(this).treegrid({ url:'/home/getData' //这里不需要自己指定id }); 就ok了
liaowanyong 2013-03-30
  • 打赏
  • 举报
回复
如楼主所说,treegrid加载时会自动在onBeforeExpand的时候回传ROW.ID值给URL, 就是说展开子节点时treegrid会在原URL加上?ID=X作为子节点的数据URL(如'../****?id=1'), 所以在treegrid的URL中就可直接实现异步,无需任何其它代码。
ji1517173346 2013-03-20
  • 打赏
  • 举报
回复
我也遇到了这个问题,请楼主把解决方案贴出来分享一下
javalhl 2013-03-06
  • 打赏
  • 举报
回复
楼主说解决了,可否把代码贴出来看下。。。
javalhl 2013-03-06
  • 打赏
  • 举报
回复
引用 2 楼 wangle1189 的回复:
JavaScript code?1234onBeforeLoad:function(row,param){if(row)$(this).treegrid('options').url='....../?parentId=row.id';}
加了这一段代码,可treegrid根本没有去请求这个url,后台都没有输出。唉,神奇了。
javalhl 2013-03-06
  • 打赏
  • 举报
回复
onBeforeLoad:function(row,param){if(row)$(this).treegrid('options').url='....../?parentId=row.id';}
zgh_mnb 2013-01-23
  • 打赏
  • 举报
回复
引用 2 楼 wangle1189 的回复:
JavaScript code ? 12345 onBeforeLoad:function(row,param){ if(row) $(this).treegrid('options').url='....../?parentId=row.id'; }
呵呵我来啦 2013-01-23
  • 打赏
  • 举报
回复
onBeforeExpand 自己就会post数据可以抓包看看 而且post就是row.id
呵呵我来啦 2013-01-23
  • 打赏
  • 举报
回复
呵呵,这个问题我研究解决了 不需要使用 append方法,还是指定url,而且不需要使用自己的ajax,它自己本身就会post数据 jquery easyui treegrid 我写了两个 action ,在onBeforeExpand里面触发一个getChild 开始加载的时候是一个getRoot url可以在data-options里写,也可以在后面的 $(function(){ $.("#tg").treegrid({ url:"/../getRoot }); 这样就行了 不过我遇到一个问题发现第一个父节点点击子节点它的缩进有问题 竟然和父节点左边的缩进一样后面的父节点就没问题呢 父节点就是根节点 第一次查询出来的不是一个…… 不过差不多弄出来了把 })
解析 2013-01-22
  • 打赏
  • 举报
回复
初次加载的时候 url:'..../?parentId=0' 这样就能实现分次装载了
加载更多回复(2)

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧