博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使easyui-tree显示到指定层次
阅读量:4071 次
发布时间:2019-05-25

本文共 1636 字,大约阅读时间需要 5 分钟。

前言

 最近工程中要求将easyui-tree的树形结构显示到指定层次,再网上搜索了一下发现没有现成的代码,稍微做了一下研究,现在贴出来供大家参考。

要求

返回的树形结构中有一个属性表示当前节点的层次,我这里是
type

代码

var expendFunction = function (treeNodes) {        //var treeNodes = $('#tt').tree('getRoots');        $(treeNodes).each(function () {            var data = $('#tt').tree('getData', this.target);            if (data.type < 2) {                $('#tt').tree('expand', this.target);                expendFunction($('#tt').tree('getChildren', this.target));            }        })    };
tt是树形结构的Id.
调用:
$('#tt').tree({    url: url,    queryParams: filter,    onLoadSuccess: function (node, data) {        if (data) {            $('#tt').tree('collapseAll');            var Roots = $('#tt').tree('getRoots');            expendFunction(Roots);        }     }});

2017年7月12日更新

近日里调程序发现需要展开的节点只有十多个,但是Js代码卡顿确有2秒以后,调试后发现easyui-tree 默认的getChildren方法得到的子节点非下级节点,而是包括是子孙级节点,子孙级节点近万条,所以导致等待时间太长。

解决方案

   easyui-tree没有提供只得到下级节点的方法,所以参用了增加扩展方法
//扩展Easyui-tree 获取一级子节点$.extend($.fn.tree.methods, {    getLeafChildren: function (jq, params) {        var nodes = [];        $(params).next().children().children("div.tree-node").each(function () {            nodes.push($(jq[0]).tree('getNode', this));        });        return nodes;    }});
注:此方法来自互联网。

代码

var expendFunction = function (treeNodes) {        //var treeNodes = $('#tt').tree('getRoots');        $(treeNodes).each(function () {            var data = $('#tt').tree('getData', this.target);            if (data.type < 2) {                $('#tt').tree('expand', this.target);                expendFunction($('#tt').tree('getLeafChildren', this.target));            }        })    };

转载地址:http://qehji.baihongyu.com/

你可能感兴趣的文章
Swift中NSRange和Range的转换
查看>>
获取App Store中App的ipa包
查看>>
iOS 关于pods-frameworks.sh:permission denied报错的解决
查看>>
设置RGBColor
查看>>
设置tabbaritem的title的颜色及按钮图片
查看>>
动态设置label的高度
查看>>
获取键盘高度,调整输入框位置
查看>>
轮番图
查看>>
设置label.text的行间距
查看>>
判断当前网络
查看>>
创建操作/删除多行数据的UITableView的细节
查看>>
验证码倒计时
查看>>
动态设置Cell的高度
查看>>
取消tableView多余的横线
查看>>
NSString MD5加密
查看>>
自定义导航条返回按钮
查看>>
数字字符串转化为时间字符串
查看>>
获取iOS版本号
查看>>
获取 一个文件 在沙盒Library/Caches/ 目录下的路径
查看>>
图片压缩
查看>>