jstree, 선택한 데이터의 부모로부터의 경로 조회 > jquery

본문 바로가기
사이트 내 전체검색

jquery

jstree, 선택한 데이터의 부모로부터의 경로 조회

페이지 정보

작성자 서방님 댓글 0건 조회 165회 작성일 19-04-16 11:37

본문

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



<div id="using_json_2"></div>


<script type="text/javascript">
<!--
// Make it a variable so you can access it later
var treeData = [
  { "id" : "ajson1", "parent" : "#", "text" : "Simple root node", "date":"2018"},
  { "id" : "ajson2", "parent" : "#", "text" : "Root node 2", "date":"2018"},
  { "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1", "date":"12" },
  { "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2", "date":"12" },
  { "id" : "ajson5", "parent" : "ajson4", "text" : "File 1", "date":"12","children": false,"icon":"fa fa-file-o"  },
  { "id" : "ajson6", "parent" : "ajson4", "text" : "File 2", "date":"12","children": false,"icon":"fa fa-file-o"  }
];

var myTree = $('#using_json_2').jstree({ 'core' : {
  'data' : treeData // Use it here
}});

myTree.on('changed.jstree', function(e, data) {
	var selected = data.instance.get_selected(),
	path = data.instance.get_path(selected, null, true), // Get the path (array of IDs, since we pass true)
	node_path = path.map(function(id) { // Use `map` to retrieve all nodes
		return treeData.find(function(node) { return node.id === id; });
	});
	console.log(node_path);

});
//-->
</script>

댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
77
어제
84
최대
1,347
전체
154,448
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.