当前位置:首页 » JavaScript技术

Jquery EasyUI Combotree和 EasyUI tree展开所有父节点

2018-05-11 11:22 本站整理 浏览(20)

 

Jquery EasyUI Combotree展开所有父节点

Jquery EasyUI Combotree获取树完整路径

Jquery EasyUI tree展开所有父节点

Jquery EasyUI tree获取完整路径

 

================================

©Copyright 蕃薯耀 2018年5月11日

http://fanshuyao.iteye.com/

 

 

/**
 * 根据叶子节点展开所有父节点
 * @param treeObj 树对象,(combotree的树对象获取:var treeObj = comboObj.combotree("tree");)
 * @param node 叶子节点
 */
function expandParent(treeObj, node){
	var parentNode = treeObj.tree("getParent", node.target);
	if(parentNode != null && parentNode != "undefined"){
		treeObj.tree("expand", parentNode.target);
		expandParent(treeObj, parentNode);
	}
};

/**
 * tree初始化赋值并展开所有父节点
 * @param treeObj 树对象
 * @param leafValue 叶子节点的值
 */
function treeInitValueAndExpand(treeObj, leafValue){
	var nodesChecked = treeObj.tree("getChecked");//获取选中的值
	if(nodesChecked.length > 0){
		for(var i=0; i<nodesChecked.length; i++){
			expandParent(treeObj, nodesChecked[i]);
		}
	}
};

/**
 * 根据叶子节点选中的值,获取树整个路径的名称
 * @param treeObj 树对象,(combotree的树对象获取:var treeObj = comboObj.combotree("tree");)
 * @param node 叶子节点
 */
function getTreePathNames(treeObj, node){
	var pathName = node.text;
	var parentNode = treeObj.tree("getParent", node.target);
	if(parentNode != null && parentNode != "undefined"){
		pathName = getTreePathNames(treeObj, parentNode) + " > " + pathName;
	}
	return pathName;
};

/**
 * 根据叶子节点选中的值,获取树整个路径的名称
 * @param combotreeId 唯一ID
 * @param leafValue 叶子节点的值
 */
function getCombotreePathNames(combotreeId, leafValue){
	var combotreeObj = $("#"+combotreeId);
	var treeObj = combotreeObj.combotree("tree");
	var nodesChecked = treeObj.tree("getChecked");//获取选中的值
	var pathName = "";
	if(nodesChecked.length > 0){
		for(var i=0; i<nodesChecked.length; i++){
			pathName += getTreePathNames(treeObj, nodesChecked[i]);
		}
	}
	return pathName;
};



/**
 * combotree初始化赋值并展开所有父节点
 * @param combotreeId 唯一ID
 * @param leafValue 叶子节点的值
 */
function combotreeInitValueAndExpand(combotreeId, leafValue){
	var combotreeObj = $("#"+combotreeId);
	var treeObj = combotreeObj.combotree("tree");
	combotreeObj.combotree("setValue", leafValue);//赋值
	treeInitValueAndExpand(treeObj, leafValue);
};

 

 

================================

©Copyright 蕃薯耀 2018年5月11日

http://fanshuyao.iteye.com/