【发布时间】:2012-03-28 16:32:47
【问题描述】:
我正在使用 jsTree jQuery 插件。我的树最初开始扩展时遇到问题。
这是用户在加载页面时看到的内容:
这是我希望用户看到的:
以下是我用于测试的 HTML。我发现这种行为是由initially_select 参数的顺序决定的。当我有'initially_select': ['2', '1'] 时,树最初显示为展开。当我有'initially_select': ['1', '2'] 时,树最初显示为关闭。通过首先选择最顶层的节点,树保持关闭状态。但是,在我的真实用例中,我的节点上有有意义的 id,它们不容易排序;我没有 [easy] 方法可以轻松确定哪些项目在我的树中“最顶层”。
我已经尝试了here 建议的解决方案。我在loaded.jstree 回调中调用了close_all,但似乎加载的事件回调在选择initially_selected 项目之前运行。因此,jsTree 会关闭所有节点(已经关闭),然后选择几个节点,导致其中许多节点再次展开。
我只想在用户加载页面时让我的 jsTree 完全折叠。
这是用于演示的 HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html lang="en">
<head>
<title>jsTree Test</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
<div id="my_tree">
<ul>
<li>
<a id="1">Item 1</a>
<ul>
<li><a id="2">Item 1.1</a></li>
</ul>
</li>
</ul>
</div>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery.jstree.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#my_tree').jstree(
{'plugins': ['themes', 'checkbox', 'html_data', 'ui'],
'checkbox': {'override_ui': true, 'real_checkboxes': true},
'ui': {'initially_select': ['2', '1']},
'themes': {'icons': false}}
);
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript tree treeview jstree