【发布时间】:2016-05-11 07:34:18
【问题描述】:
我编写了显示 jstree 和复选框的程序。 我写了一个事件来检查复选框是否被选中,所以当我删除该代码时, jstree 变得可见,并且当该代码存在时,不会显示树。
这是我的代码
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
html { margin:0; padding:0; font-size:62.5%; }
body { max-width:300px; min-width:100px; padding:20px 10px; font-size:14px; font-size:1.4em; }
h1 { font-size:1.8em; }
.demo { overflow:auto; border:1px solid silver; min-height:100px; }
</style>
<link rel="stylesheet" href="style.min.css" />
</head>
<body>
<div id="frmt" class="demo"></div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="jstree.min.js"></script>
<button>>></button>
<script>
var a=[{"id":"Name 1","text":"name1","children":[{"id":"Name 2","text":"Name 2"}]}];
</script>
<script>
$('#html').jstree();
$('#frmt').jstree({
'core': {
'data':a
},
"checkbox" : {
"whole_node" : false,
"keep_selected_style" : true,
"three_state" : true,
"tie_selection" : false
}, "search" : {
"fuzzy" : true
},"plugins" : [ "checkbox", "search" ]
});
$('#frmt').on("changed.jstree", function (e, data) {
console.log("Length : "+data.selected.length);
if(data.selected.length>0)
{
$(data.selected).each(function idx{
var node=data.data.instance.get_node(data.selected(idx));
console.log("Selected Node is : "+node.text);
});
}
});
$('button').on('click', function () {
alert($('#frmt').jstree("get_selected"));
});
</script>
</body>
</html>
因此,使用此代码,它不会显示 jstree
当我删除时
$('#frmt').on("changed.jstree", function (e, data) {
console.log("Length : "+data.selected.length);
if(data.selected.length>0)
{
$(data.selected).each(function idx{
var node=data.data.instance.get_node(data.selected(idx));
console.log("Selected Node is : "+node.text);
});
}
});
它显示了树
【问题讨论】:
-
你试过调试吗?例如插入“调试器;”在“function(e,data){”之后去Chrome开发者工具(如果你使用Chrome的话)调试回调?
-
是的,但那边没有错误
标签: javascript jquery html jstree