jstree使用心得

jstree官网:https://www.jstree.com/

1.需要导入的文件

<link rel="stylesheet" href="dist/themes/default/style.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<script src="dist/jstree.min.js"></script>


2.在页面上创建一个jstree容器(div)

<div id="jstree_demo_div"></div>

3.创建一个jstree实例

<script type="text/javascript">
	$('#jstree_demo_div1').jstree({'plugins':["wholerow","checkBox"],'core' : {
		'data' : [
			{
				"text" : "Same but with checkBoxes","children" : [
					{ "text" : "initially selected","state" : { "selected" : true } },{ "text" : "custom icon URL"},{ "text" : "initially open","state" : { "opened" : true },"children" : [ "Another node" ] },{ "text" : "custom icon class"}
				]
			},"And wholerow selection"
		]
	}});
</script>

效果


4.ajax动态加载jstree

$.getJSON("/Fims/api/rest/RolePermission/loadPermissionTreeData",{ts_role_id:ts_role_id},function(json){
		$('#rolePermissionTree').jstree({'plugins':['checkBox'],'core' : {
				'data' : json.datalist
		}});
	}
);

5.清空树(数据库的信息更新后想要刷新树,先要清空树)

$('#perjstree').data('jstree',false).empty();

6.绑定节点点击事件

$('#orgjstree').bind("activate_node.jstree",function (obj,e) {
	// 获取当前节点
	alert(e.node.id);//得到被点击节点的id
});

7.得到所有被选中的节点的id(先加上'plugins':["checkBox"],使所有的节点前面加上checkBox

var ids = $('#rolePermissionTree').jstree().get_checked(); 



相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...