zTree实现获取一级节点数据

1、实现源码

<!DOCTYPE html>
<html>
<head>
	<title>zTree实现基本树</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="../../../css/demo.css">
	<link rel="stylesheet" type="text/css" href="../../../css/zTreeStyle/zTreeStyle.css">
	<script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
	<script type="text/javascript">
		<!--
		var setting = {
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		var zNodes =[
			{ id:1, pId:0, name:"湖北省", open:true},
			{ id:11, pId:1, name:"武汉市", open:true},
			{ id:111, pId:11, name:"汉口"},
			{ id:112, pId:11, name:"汉阳"},
			{ id:113, pId:11, name:"武昌"},
			{ id:12, pId:1, name:"黄石市"},
			{ id:121, pId:12, name:"黄石港区"},
			{ id:122, pId:12, name:"西塞山区"},
			{ id:123, pId:12, name:"下陆区"},
			{ id:124, pId:12, name:"铁山区"},
			{ id:13, pId:1, name:"黄冈市"},
			{ id:131, pId:13, name:"黄州区"},
			{ id:132, pId:13, name:"麻城市"},
			{ id:133, pId:13, name:"武穴市"},
			{ id:134, pId:13, name:"团风县"},
			{ id:135, pId:13, name:"浠水县"},
			{ id:136, pId:13, name:"罗田县"},
			{ id:137, pId:13, name:"英山县"},
			{ id:2, pId:0, name:"湖南省", open:true},
			{ id:21, pId:2, name:"长沙市", open:true},
			{ id:211, pId:21, name:"芙蓉区"},
			{ id:212, pId:21, name:"天心区"},
			{ id:213, pId:21, name:"岳麓区"},
			{ id:214, pId:21, name:"开福区"},
			{ id:22, pId:2, name:"株洲市"},
			{ id:221, pId:22, name:"天元区"},
			{ id:222, pId:22, name:"荷塘区"},
			{ id:223, pId:22, name:"芦淞区"},
			{ id:224, pId:22, name:"石峰区"}
		];

		$(document).ready(function(){
			$.fn.zTree.init($("#baseTree"), setting, zNodes);
		});

		/**
		 * 获取全部节点数据
		 * 一级节点数据
		 */
		function findNodes()
		{
		    var treeObj = $.fn.zTree.getZTreeObj("baseTree");
		    //获取全部节点数据
			var nodes = treeObj.getNodes();
			for (var i=0, l=nodes.length; i < l; i++)
			{
			    var nodeId = nodes[i].id;
			    var nodeName = nodes[i].name;
			    alert("树节点编码:"+nodeId+"\n"+"树节点名称:"+nodeName);
			}
		}
		//-->
	</script>
 </head>

<body>
<div class="content_wrap">
	<div class="zTreeDemoBackground left" style="text-align: center;">
		<ul id="baseTree" class="ztree" style="height: 300px; width:200px; overflow-y: auto"></ul>
		<input type="button" id="btn" onclick="findNodes()" value="获取全部节点数据"/>
	</div>
</div>
</body>
</html>

2、实现结果

(1)初始化

(2)单击“获取全部节点数据”

(3)单击“确定”

3、源码说明

var treeObj = $.fn.zTree.getZTreeObj("baseTree");
//获取全部节点数据
var nodes = treeObj.getNodes();

获取全部一级节点数据

zTree实现获取一级节点数据

时间: 2024-11-02 23:35:33

zTree实现获取一级节点数据的相关文章

ztree中获取选中节点下的所有叶子节点

ztree中获取选中节点下的所有叶子节点 var setting = {     data: {         simpleData: {             enable: true        }     },     callback: {         onClick: treenodeClick     } }; //点击树节点,获取节点的所有叶子节点idfunction treenodeClick(event, treeId, treeNode, clickFlag) {

160420、zTree获取所有选中节点数据

<!DOCTYPE html><HTML><HEAD> <TITLE> ZTREE DEMO - Standard Data </TITLE> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="css/zTreeSty

ztree获取选中节点时不能进入可视区域出现BUG如何解决

zTree 是一个依靠 jQuery 实现的多功能 "树插件".优异的性能.灵活的配置.多种功能的组合是 zTree 最大优点. zTree 的特点编辑 ● zTree v3.0 将核心代码按照功能进行了分割,不需要的代码可以不用加载● 采用了延迟加载技术,上万节点轻松加载,即使在 IE6 下也能基本做到秒杀● 兼容 IE.FireFox.Chrome.Opera.Safari 等浏览器● 支持 JSON 数据● 支持静态和 Ajax 异步加载节点数据● 支持任意更换皮肤 / 自定义图

ztree 修改数据 默认勾选节点 数据回显

var treeObj = $.fn.zTree.getZTreeObj(treeid); var data = $("#hiddentree"+'${model.objUid}').val(); var datas = data.split(','); var inputtree = ''; var d = ''; for(var i = 0;i<datas.length;i++){ treeObj.checkNode(treeObj.getNodesByParam("

zTree实现获取当前选中的第一个节点在同级节点中的序号

1.实现源码 <!DOCTYPE html> <html> <head> <title>zTree实现基本树</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href=&

ztree获取选中节点

$(document).ready(function(){ $.fn.zTree.init($("#treeDemo"), setting, zNodes); }); function onCheck(e,treeId,treeNode){ var treeObj=$.fn.zTree.getZTreeObj("treeDemo"), nodes=treeObj.getCheckedNodes(true), v=""; for(var i=0;i

获取jquery 返回xml类型的data的子节点数据

<packet version="1.0.0"> <status>success</status> <data> <item> <id>4b6a3c233b4cb</id> <count_view>41</count_view> <updated>2010-03-04 17:08:28</updated> </item> </data&g

ztree 获取子节点所有父节点的name的拼接

//获取子节点,所有父节点的name的拼接字符串function getFilePath(treeObj){if(treeObj==null)return "";var filename = treeObj.name;var pNode = treeObj.getParentNode();if(pNode!=null){filename = getFilePath(pNode) +">"+ filename;}return filename;} 原文地址:ht

zTree根据json选中节点,并且设置其他节点不可选

首先,在适配目录树时,使用checkbox形式,配置代码如下: 看下效果: 这时的每个节点都处于一个可选的状态(但都未选中),但在实际项目中我们可能还会遇到另外两种情况: 1.根据后台返回的json,选中指定节点(此时所有的节点仍处于可编辑的状态): 代码如下: var treeObj = $.fn.zTree.getZtreeObj("categoryTree"); for(var j = 0; j < zNodes.length; j++){ treeObj.checkNod