jQuery动态树不工作

jQuery动态树不工作,jquery,jsp,dynatree,Jquery,Jsp,Dynatree,我正在尝试让DynaTree第一次使用它工作,而不是运气-树只是显示为一个常规的HTML列表。我肯定这是件小事,但我没看到 以下是我的文件结构: 这是树所在的页面result.jsp: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//

我正在尝试让DynaTree第一次使用它工作,而不是运气-树只是显示为一个常规的HTML列表。我肯定这是件小事,但我没看到

以下是我的文件结构:

这是树所在的页面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>

有什么想法吗?谢谢标记

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

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

1保留无序列表,从脚本中删除生成 像默认的那样

<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对象,删除无序列表 类似于JS对象中的in-init

<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"}
      ]
    });
});

什么不起作用?您看到了什么错误或没有看到什么错误?抱歉-没有错误,只是树显示为常规列表。OMG!就这样。啊。在这么简单的事情上花了这么多时间。。。非常感谢。你是对的,我试过多种不同的方法。原来问题是JS文件dynatree在UI之前的顺序-见mar10的答案。