JSTree链接不起作用

时间:2014-06-03 19:06:42

标签: jquery jstree

如何允许/启用与jstree的链接?我希望能够单击根旁边的箭头来展开树(如果适用),还希望使文本可链接?当我点击我的链接没有任何反应。例如,我点击谷歌旁边的箭头应该展开树,但点击谷歌应该带我到谷歌。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>jsTree test</title>
  <!-- 2 load the theme CSS file -->
  <link rel="stylesheet" href="http://static.jstree.com/3.0.1/assets/dist/themes/default/style.min.css" />
</head>
<body>
  <!-- 3 setup a container element -->
  <div id="jstree">
    <!-- in this example the tree is populated from inline HTML -->
    <ul>
      <li><a href="http://www.google.com">Google</a>
        <ul>
          <li id="child_node_1"><a href="http://www.yahoo.com">Yahoo</a></li>
          <li><a href="http://www.outlook.com">Outlook</a></li>
        </ul>
      </li>
      <li><a href="http://www.espn.com">Espn</a></li>
    </ul>
  </div>


  <!-- 4 include the jQuery library -->
  <script src="http://static.jstree.com/3.0.1/assets/jquery-1.10.2.min.js"></script>
  <!-- 5 include the minified jstree source -->
  <script src="http://static.jstree.com/3.0.1/assets/dist/jstree.min.js"></script>
  <script>
  $(function () {
    // 6 create an instance when the DOM is ready
    $('#jstree').jstree();
    // 7 bind to events triggered on the tree
    $('#jstree').on("changed.jstree", function (e, data) {
      console.log(data.selected);
    });




  });
  </script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试这个jsTree事件处理程序:

$('#jstree').on("select_node.jstree", function (e, data) { //open google in browser });

我希望这就是你要找的东西。