easyui combotree 异步加载节点 默认值 问题

关于easyui combotree在异步加载子节点的时候由于没有加载的层级比较深的子节点,那么默认值就会直接是以id的形式显示的combotree的文本框中,因为这个时候需要被匹配的那个节点根本没有加载出来,所以只能显示id。

网上基本上没有这个问题的解决方案,研究了一下想到了一个解决方案,暂且不说是最好的,但是至少能解决问题,下面开始讲解。

楼主我通过在combotree初始化时在onLoadSuccess事件中调用一个自定义函数来进行初始化。下面这个combotree是异步加载子节点,异步加载原理是什么这不是讨论重点。

来说一说思路,defalutValue函数通过对combotree的tree对象追加一个用户想要的默认值节点,并使其隐藏来达到设置默认值的效果。

$("#moduls_funbase_sysmgr_addUnit_combotree").combotree({
	url : '${pageContext.request.contextPath}/base_sysmgr_demoController/getUnitParamTree.do?superunitid1=',
	valueField:'id',
	textField:'text',
	parentField:'pid',
	panelWidth:'200',
	onClick : function(node) {
		//console.log(node);
    },
    onBeforeExpand:function(node,param){
        $(this).tree('options').url = 
        	'${pageContext.request.contextPath}/base_sysmgr_demoController/getUnitParamTree.do?superunitid1='+node.id;                  
    },
    onLoadSuccess:function(node,data){

	    	defaultValue('moduls_funbase_sysmgr_addUnit_combotree','100','默认值文本');//这个方法就是解决默认值的问题核心
    	
    }
});

//slk/2015-12-10
//为combotree增加默认值隐藏节点,解决因异步加载导致默认值id直接显示到文本框中的问题
//cbtid:combotree的id
//defval:生成节点的id
//deftext:生成节点的文本用于显示
function defaultValue(cbtid,defVal,defText){
	var combotree =$("#"+cbtid);
	var tree = combotree.combotree('tree');
	var defNode = tree.tree("find",defVal);
	if(!defNode){
		tree.tree('append', {
			data: [{
				id: defVal,
				text: defText
			}]
		});
		defNode = tree.tree("find",defVal);
		//console.log(defNode);
		//console.log(combotree);
		combotree.combotree('setValue',defVal);
		tree.tree('select',defNode.target);
		defNode.target.style.display='none';
	}else{
		combotree.combotree('setValue',defVal);
	}
}

这个时候,就已经设置完成,默认值文本为‘默认值文本’,默认值为‘100’。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值