jQuery DynaTree 不工作

发布于 2024-12-26 13:33:21 字数 4676 浏览 5 评论 0原文

我试图让 DynaTree(第一次使用它)工作,但运气不好 - “树”只是显示为常规 HTML 列表。我确信这是一件微不足道的事情,但我没有看到它。

这是我的文件结构: DynaTree 项目文件

这是树所在的页面 (result.jsp):

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>IDT HL7 Search Results</title>
  <link rel="stylesheet" type="text/css" href="css/messaging.css" />
  <link rel="stylesheet" type="text/css" href="css/ui.dynatree.css" />
  <script type="text/javascript" src="js/jquery-1.7.1.js"></script>
  <script type="text/javascript" src="js/jquery.dynatree.js"></script>
  <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
  <script type="text/javascript" src="js/jquery.cookies.2.2.0.js"></script>
  <!-- Add code to initialize the tree when the document is loaded: -->
  <script type="text/javascript">
$(document).ready(function() {
    // Attach the dynatree widget to an existing <div id="tree"> element
    // and pass the tree options as an argument to the dynatree() function:
    $("#tree").dynatree({
      onActivate: function(node) {
        // A DynaTreeNode object is passed to the activation handler
        // Note: we also get this event, if persistence is on, and the page is reloaded.
        alert("You activated " + node.data.title);
      },
      children: [
        {title: "Item 1"},
        {title: "Folder 2", isFolder: true, key: "folder2",
          children: [
            {title: "Sub-item 2.1"},
            {title: "Sub-item 2.2"}
          ]
        },
        {title: "Item 3"}
      ]
    });
    $("a").click(function() {
     alert("Hello world!");
    });
  });
  </script>
</head>
<body>
<h2 class="center">IDT HL7 Search Results</h2>
<div id="search">
    <fieldset class="search-fields">
        <legend>Currently viewing</legend>
        Site: <input type="text" name="currentSite" disabled="disabled" value=<%= request.getParameter("searchFor") %> />
        CSID: <input type="text" name="currentCsid" disabled="disabled" value=<%= request.getAttribute("csidValue") %> />
        RCR:  <input type="text" name="currentRcr"  disabled="disabled" />
        <a href="index.jsp"><b>New Search</b></a>
    </fieldset>
</div>
<br/>
<div>
    <form>
        <input type="checkbox" name="filterBy" value="Filter by:" /> Filter results by:
        <input type="text" name="filterBy" />
    </form>
</div>
<br/>
<div id="content">
   <div id="sub-left">
    <fieldset class="search-fields">
        <legend>Files Found</legend>
        <!-- Add a <div> element where the tree should appear: -->
        <div id="tree"> 
            <ul>
       <li>Orders
         <ul>
           <li>From Client
              <ul>
                <li> document 1.1.1</li>
                <li> document 1.1.2</li>
               </ul>
            </li>  
            <li>To Lab
               <ul>
                 <li>document 1.2.1</li>
                 <li>document 1.2.2</li>
               </ul>
           </li>
        </ul>
     </li>
     <li> Results
        <ul>
          <li> From Lab
            <ul>
               <li>document 2.1.1</li>
               <li>document 2.1.2</li>
            </ul>
          </li>
            <li>To Client
               <ul>
                 <li>document 2.2.1</li>
                 <li>document 2.2.2</li>
               </ul>
           </li>
        </ul>
      </li>
    </ul>
        </div>
      </fieldset>
   </div>
   <div id="sub-right">
     <fieldset class="search-fields">
        <legend>Selected File Contents</legend>
        <textarea rows="14" wrap="soft" readonly="readonly">
(select via tree on left)
        </textarea>
     </fieldset>
   </div>
   <div class="clear-both"></div>
</div>
</body>
</html>

有什么想法吗?谢谢!标记

I am trying to get a DynaTree (first use of it) working w/o luck - the "tree" just shows up as a regular HTML list. I'm sure it's something trivial but I'm not seeing it.

Here is my file structure:
DynaTree project files

This is the page (result.jsp) that the tree is on:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>IDT HL7 Search Results</title>
  <link rel="stylesheet" type="text/css" href="css/messaging.css" />
  <link rel="stylesheet" type="text/css" href="css/ui.dynatree.css" />
  <script type="text/javascript" src="js/jquery-1.7.1.js"></script>
  <script type="text/javascript" src="js/jquery.dynatree.js"></script>
  <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
  <script type="text/javascript" src="js/jquery.cookies.2.2.0.js"></script>
  <!-- Add code to initialize the tree when the document is loaded: -->
  <script type="text/javascript">
$(document).ready(function() {
    // Attach the dynatree widget to an existing <div id="tree"> element
    // and pass the tree options as an argument to the dynatree() function:
    $("#tree").dynatree({
      onActivate: function(node) {
        // A DynaTreeNode object is passed to the activation handler
        // Note: we also get this event, if persistence is on, and the page is reloaded.
        alert("You activated " + node.data.title);
      },
      children: [
        {title: "Item 1"},
        {title: "Folder 2", isFolder: true, key: "folder2",
          children: [
            {title: "Sub-item 2.1"},
            {title: "Sub-item 2.2"}
          ]
        },
        {title: "Item 3"}
      ]
    });
    $("a").click(function() {
     alert("Hello world!");
    });
  });
  </script>
</head>
<body>
<h2 class="center">IDT HL7 Search Results</h2>
<div id="search">
    <fieldset class="search-fields">
        <legend>Currently viewing</legend>
        Site: <input type="text" name="currentSite" disabled="disabled" value=<%= request.getParameter("searchFor") %> />
        CSID: <input type="text" name="currentCsid" disabled="disabled" value=<%= request.getAttribute("csidValue") %> />
        RCR:  <input type="text" name="currentRcr"  disabled="disabled" />
        <a href="index.jsp"><b>New Search</b></a>
    </fieldset>
</div>
<br/>
<div>
    <form>
        <input type="checkbox" name="filterBy" value="Filter by:" /> Filter results by:
        <input type="text" name="filterBy" />
    </form>
</div>
<br/>
<div id="content">
   <div id="sub-left">
    <fieldset class="search-fields">
        <legend>Files Found</legend>
        <!-- Add a <div> element where the tree should appear: -->
        <div id="tree"> 
            <ul>
       <li>Orders
         <ul>
           <li>From Client
              <ul>
                <li> document 1.1.1</li>
                <li> document 1.1.2</li>
               </ul>
            </li>  
            <li>To Lab
               <ul>
                 <li>document 1.2.1</li>
                 <li>document 1.2.2</li>
               </ul>
           </li>
        </ul>
     </li>
     <li> Results
        <ul>
          <li> From Lab
            <ul>
               <li>document 2.1.1</li>
               <li>document 2.1.2</li>
            </ul>
          </li>
            <li>To Client
               <ul>
                 <li>document 2.2.1</li>
                 <li>document 2.2.2</li>
               </ul>
           </li>
        </ul>
      </li>
    </ul>
        </div>
      </fieldset>
   </div>
   <div id="sub-right">
     <fieldset class="search-fields">
        <legend>Selected File Contents</legend>
        <textarea rows="14" wrap="soft" readonly="readonly">
(select via tree on left)
        </textarea>
     </fieldset>
   </div>
   <div class="clear-both"></div>
</div>
</body>
</html>

Any ideas? Thanks! Mark

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你又不是我 2025-01-02 13:33:21

您必须在 dynatree 之前包含 jquery 和 jquery-ui

You must include jquery and jquery-ui before dynatree

不羁少年 2025-01-02 13:33:21

我看到你一次混合了两个例子。您尝试同时启动 dynatree 和 javascript 对象。仅使用一个来启动:

1)保留无序列表,从脚本中删除生成
(如 http://wwwendt.de/tech/dynatree/doc/samples.html< /a> - 默认)

<div id="tree">
    <ul>
        <li>Orders
        <ul>
            <li>From Client
            <ul>
                <li> document 1.1.1</li>
                <li> document 1.1.2</li>
            </ul>
            </li>
            <li>To Lab
            <ul>
                <li>document 1.2.1</li>
                <li>document 1.2.2</li>
            </ul>
            </li>
        </ul>
        </li>
        <li> Results
        <ul>
            <li> From Lab
            <ul>
                <li>document 2.1.1</li>
                <li>document 2.1.2</li>
            </ul>
            </li>
            <li>To Client
            <ul>
                <li>document 2.2.1</li>
                <li>document 2.2.2</li>
            </ul>
            </li>
        </ul>
        </li>
    </ul>
</div>

$(document).ready(function() {
    $("#tree").dynatree();
});

2) 保留 javascript 对象,删除无序列表
(如 http://wwwendt.de/tech/dynatree/doc/samples.html< /a> - 从 JS 对象初始化)

<div id="tree"></div>

$(document).ready(function() {
$("#tree").dynatree({
      onActivate: function(node) {
        // A DynaTreeNode object is passed to the activation handler
        // Note: we also get this event, if persistence is on, and the page is reloaded.
        alert("You activated " + node.data.title);
      },
      children: [
        {title: "Item 1"},
        {title: "Folder 2", isFolder: true, key: "folder2",
          children: [
            {title: "Sub-item 2.1"},
            {title: "Sub-item 2.2"}
          ]
        },
        {title: "Item 3"}
      ]
    });
});

I see you have mixed two examples at a time. You try to initiate dynatree on and javascript object in the same time. Use only one to initiate:

1) Leave unordered list, delete generation from script
(like in http://wwwendt.de/tech/dynatree/doc/samples.html - Default)

<div id="tree">
    <ul>
        <li>Orders
        <ul>
            <li>From Client
            <ul>
                <li> document 1.1.1</li>
                <li> document 1.1.2</li>
            </ul>
            </li>
            <li>To Lab
            <ul>
                <li>document 1.2.1</li>
                <li>document 1.2.2</li>
            </ul>
            </li>
        </ul>
        </li>
        <li> Results
        <ul>
            <li> From Lab
            <ul>
                <li>document 2.1.1</li>
                <li>document 2.1.2</li>
            </ul>
            </li>
            <li>To Client
            <ul>
                <li>document 2.2.1</li>
                <li>document 2.2.2</li>
            </ul>
            </li>
        </ul>
        </li>
    </ul>
</div>

$(document).ready(function() {
    $("#tree").dynatree();
});

2) Leave javascript object, delete unordered list
(like in http://wwwendt.de/tech/dynatree/doc/samples.html - init from JS object)

<div id="tree"></div>

$(document).ready(function() {
$("#tree").dynatree({
      onActivate: function(node) {
        // A DynaTreeNode object is passed to the activation handler
        // Note: we also get this event, if persistence is on, and the page is reloaded.
        alert("You activated " + node.data.title);
      },
      children: [
        {title: "Item 1"},
        {title: "Folder 2", isFolder: true, key: "folder2",
          children: [
            {title: "Sub-item 2.1"},
            {title: "Sub-item 2.2"}
          ]
        },
        {title: "Item 3"}
      ]
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文