首页 技术 正文
技术 2022年11月15日
0 收藏 769 点赞 2,341 浏览 1120 个字

感觉easyUi 的树用起来不如 Ext 的树方便,首先,root节点不太好自定义,

异步加载时,只能通过后台判断生成root节点,但是这样一来有一个问题,就是第一次访问界面时,

树的初始化比较慢,大概会有一秒左右的时间,树是空白的,虽然只有一秒左右的时间,但是对于我来说是没有办法容忍的,所以,我是用 ajax 的方法通过append 将子节点加入进去,然后展开所有节点,并且默认选择第一个子节点

下面是 js 代码

$(document).ready(function(){
$("#tree").tree({
data: [{
text: '主目录',
state: 'closed'
}],
onSelect: function(selectNode){
console.log("select: " + selectNode.id);
}
});$.ajax({
type : "POST",
dataType : "json",
url : "testAction_loadTree",
success : function(data){
var rootNode = $("#tree").tree('getRoot');
/* 向root添加子节点 */
$("#tree").tree('append',{
parent: rootNode.target,
data: data
});/* 展开所有节点 */
$("#tree").tree('expandAll');var children = $("#tree").tree('getChildren',rootNode.target);/* 选中第一个子节点 */
$("#tree").tree("select",children[0].target);
}
});
});

ajax 通过后台传递的json数据格式为:

[{"id":"D:\\lucene\\file5\\index","state":"open","text":"D:\\lucene\\file5\\index"},{"id":"D:\\lucene\\file5\\indexwa","state":"open","text":"D:\\lucene\\file5\\indexwa"},{"id":"D:\\lucene\\file5\\index_tmp","state":"open","text":"D:\\lucene\\file5\\index_tmp"},{"id":"D:\\lucene\\file5\\spider","state":"open","text":"D:\\lucene\\file5\\spider"}]

json 是通过fastJson 这个开源的java 工具实现的,挺好用的,在此推荐一下

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838