Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

combotree:模糊查询及展示到第2层

部分文档来源说明:【EasyUI】combotree和combobox模糊查询

/* easyuiTreeLoad:start  */
var pidSet = new Set();

function initSet(data){
	for ( var i = 0; i < data.length; i++) {
		pidSet.add(data[i].pid);
	}
}

function easyuiTreeLoad(combotreeId, url, rootId, queryParams) {
	$("#" + combotreeId).combotree({
		lines : true,
		url : url,
		queryParams:queryParams,
		// 1、过滤数据显示
		valueField : 'id',
		textField : 'text',
		editable : false,
		cascadeCheck:false,
		multiple:false,
		collapse:true,
		loadFilter : function(data) {
			initSet(data);
			return getDepartmentTree(rootId, data);
		},
		onLoadSuccess:function(node1,data){
			/* combotree:仅展示到第2层:start*/
			var ds=$('#unitSel').combotree('tree').tree('find', data[0].id);
			$('#unitSel').combotree('tree').tree('collapseAll');
			$('#unitSel').combotree('tree').tree('expand', ds.target);
			/* combotree:仅展示到第2层:start*/
			
		}
	});
}
function getDepartmentTree(rootId, data) {
	var departmentTree = '';
	
	for ( var i = 0; i < data.length; i++) {
		var departmentNode = null;
		if (data[i].pid == rootId) {
			departmentNode = "{\"id\":\"" + data[i].id + "\",\"text\":\"" + data[i].name +"\"";
			// 调用findChild方法,开始遍历整个树,寻找当前节点的子节点。
			if(pidSet.has(data[i].id)){
				var child = findChild(data[i].id, data);
				if (child != null) {
					departmentNode += child;
				}
			}
			
			departmentNode += "}";
			
			if(departmentTree != ''){
				departmentTree += "," +departmentNode;
			}else{
				departmentTree = departmentNode;
			}
		}
		
	}
	departmentTree = "[" + departmentTree + "]";
	return JSON.parse(departmentTree);
}

function findChild(rootId, data) {
	var departmentTree = '';
	for ( var i = 0; i < data.length; i++) {
		var departmentNode = null;
		if (data[i].pid == rootId) {
			departmentNode = "{\"id\":\"" + data[i].id + "\",\"text\":\"" + data[i].name +"\"";
			// 调用findChild方法,开始遍历整个树,寻找当前节点的子节点。
			if(pidSet.has(data[i].id)){
				var child = findChild(data[i].id, data);
				if (child != null) {
					departmentNode += child;
				}
			}
			
			departmentNode += "}";
			
			if(departmentTree != ''){
				departmentTree += "," +departmentNode;
			}else{
				departmentTree = departmentNode;
			}
		}
		
	}
	departmentTree = ",\"children\":[" + departmentTree + "]";
	return departmentTree;
}

/* easyuiTreeLoad:end  */

/* combotree:支持模糊查询:start*/
(function(){  
    $.fn.combotree.defaults.editable = true;  
    $.extend($.fn.combotree.defaults.keyHandler,{  
        up:function(){  
            console.log('up');  
        },  
        down:function(){  
            console.log('down');  
        },  
        enter:function(){  
            console.log('enter');  
        },  
        query:function(q){  
        	$(this).combotree('tree').tree('expandAll');	//由于模糊查询不到隐藏的结构,故先展示全部结构
            var t = $(this).combotree('tree');  
            var nodes = t.tree('getChildren');  
            for(var i=0; i<nodes.length; i++){  
                var node = nodes[i];  
                if (node.text.indexOf(q) >= 0){  
                    $(node.target).show();  
                } else {  
                    $(node.target).hide();  
                }  
            }  
            var opts = $(this).combotree('options');  
            if (!opts.hasSetEvents){  
                opts.hasSetEvents = true;  
                var onShowPanel = opts.onShowPanel;  
                opts.onShowPanel = function(){  
                    var nodes = t.tree('getChildren');  
                    for(var i=0; i<nodes.length; i++){  
                        $(nodes[i].target).show();  
                    }  
                    onShowPanel.call(this);  
                };  
                $(this).combo('options').onShowPanel = opts.onShowPanel;  
            }  
        }  
    });  
})(jQuery);
/* combotree:支持模糊查询:end*/
<select id="unitSel" name="unitSel" style="width:200px" class="easyui-combotree"></select>
easyuiTreeLoad('unitSel', rootPath + '/zzjg/getZzjgTreeBySession.do','root',null);
<select id="getZzjgTreeBySession" resultMap="zzjgTreeMap">
	select id, zzjgjc, nvl(parent_id, 'root') parent_id, 0 as checked, shortdm
	from t_sys_zzjg
	<if test="_parameter != null and _parameter !=''">
		connect by prior zzjgdm = parent_id start with zzjgdm = #{_parameter} 
	</if> 
	order by id, show_index asc
</select>

 

添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值