jstree心得

本文参考http://blog.csdn.net/m0_37355951/article/details/78004994?locationNum=4&fps=1

用jstreel是因为公司要用一下无限极的树结构;而后台给的数据又不是同一种代码风格

代码如下``` <!doctype html>

<html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <title>jstree 插件</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script> </head> <body> <div id="jstree"></div> <script type="text/javascript"> var isclick=true; $(function () { $('#jstree').jstree({ // 'plugins': ["checkbox", "state"], 'core': { 'data': [{ "id": "root", "text": "sxsf", "state": { //默认状态展开 "opened": true }, "children": [] }], 'check_callback': true } }); });

function gettree(parentsid){
	
	$.ajax({
		type:"get",
         url:parentsid=="root"?"getFacultyListByUserIdAndCollegeIdLast":"getNextFacultyListById",
		async:true,
		data:{
			tokenId:tokenId,
			userId:userId,
			collegeId:collegeId,
			id:parentsid
		},
		success:function(res){
			if(res.code==200){
				var data=res;
				$.each((parentsid=="root"?data.body:data.body.list),function(index,obj){
					obj.text=obj.name;
					createNode("#"+parentsid, obj.id, obj.name,"last");
				})
				isclick=true;
			}
		}
	});
}

// API createNode(parent, id, text, position).     
//  parent:在该节点下创建,id: 新节点id, text:新节点文本, position:插入位置  
// 封装一个函数动态创建节点  
function createNode(parent_node, new_node_id, new_node_text, position) { 
	debugger;
    	if($("#"+new_node_id).length>0){//此处是为了防止重复创建
    		
    	}else{
    		$('#jstree').jstree('create_node', $(parent_node), { 
    			"text":new_node_text, 
    			"id":new_node_id,
    			"children": [],
    			"state": {    //默认状态展开
                    "opened": true  
                }   
    		}, position, false, false);
    	}
}  

</script>  

</body> </html> ```

转载于:https://my.oschina.net/u/3392853/blog/1609291

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值