我有一个使用jstree插件的程序。一个带有层次数据的json文件被用作输入。你可以看到下面这个程序的代码示例。
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Simple 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>
<script type="text/javascript">
$(function () {
var jsondata = [
{ "id": 1, "parent": "#", "text": "Math" ,"icon":false},
{ "id": 2, "parent": 1, "text": "Algebra","icon":false },
{ "id": 3, "parent": 2, "text": "Polynomials","icon":false },
{ "id": 4, "parent": 3,"disabled":true, "text": "sum of polynomials","icon":false },
{ "id": 5, "parent": "#", "text": "Physics","icon":false },
{ "id": 6, "parent": 5, "text": "Mechanics","icon":false },
{ "id": 7, "parent": 6, "text": "Kinematics","icon":false },
{ "id": 8, "parent": 6, "text": "Dynamics","icon":false },
];
createJSTree(jsondata);
});
function createJSTree(jsondata) {
$('#SimpleJSTree').jstree({
"core": {
'data': jsondata,
"multiple" : false
},
"plugins": ["search", "checkbox"],
"search": {
"case_sensitive": false,
"show_only_matches": true
}
});
}
$(document).ready(function () {
$(".search-input").keyup(function () {
var searchString = $(this).val();
$('#SimpleJSTree').jstree('search', searchString);
});
});
</script>
</head>
<body>
<input id="search-input" class="search-input" />
<br />
<div id="SimpleJSTree"></div>
</body>
</html>
我需要得到所有选定值的id数组。我应该如何解决这个问题
1条答案
按热度按时间a64a0gku1#
我会尝试,例如在事件
select_node
上: