2013-02-14 14 views
4

我想實現的jQuery FancyTree http://wwwendt.de/tech/fancytree/demo/https://code.google.com/p/fancytree/jQuery的花式樹與本地陣列數據

這指本地陣列數據

是代碼。但它不工作,沒有腳本錯誤。但樹是空的!

即使我複製的文件,他們在演示 網站使用jQuery,UI版本。不過沒有什麼作品

<html> 
<head> 
    <script src="jquery.js" type="text/javascript"></script> 
    <script src="jquery-ui.custom.js" type="text/javascript"></script> 
    <link href="ui.fancytree.css" rel="stylesheet" type="text/css" /> 
    <script src="jquery.fancytree.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     $(function() { 
      $("#tree").fancytree({ 
       onActivate: function (node) { 
        // A DynaTreeNode object is passed to the activation handler 

        // Note: we also get this event, if persistence is on, and the 
        // age is reloaded. 
        alert("You activated " + node.data.title); 
       }, 

       children: [ // Pass an array of nodes. 
       {title: "Item 1" }, 
       { title: "Folder 2", isFolder: true, 
        children: [ 
         { title: "Sub-item 2.1" }, 
         { title: "Sub-item 2.2" } 
        ] 
       }, 
       { title: "Item 3" } 
      ] 
      }); 
     }); 

    </script> 
</head> 
<body> 
    <div id="tree"> 
    </div> 
</body> 
</html> 

回答

4

我注意到,source:[]是你如何初始化樹$("#tabTree").fancytree()初始化時調用,所以你的例子是:

<html> 
<head> 
    <script src="jquery.js" type="text/javascript"></script> 
    <script src="jquery-ui.custom.js" type="text/javascript"></script> 
    <link href="ui.fancytree.css" rel="stylesheet" type="text/css" /> 
    <script src="jquery.fancytree.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     $(function() { 
      $("#tree").fancytree({ 
       onActivate: function (node) { 
        // A DynaTreeNode object is passed to the activation handler 

        // Note: we also get this event, if persistence is on, and the 
        // age is reloaded. 
        alert("You activated " + node.data.title); 
       }, 
       source: [ // Pass an array of nodes. 
       {title: "Item 1" }, 
       { title: "Folder 2", isFolder: true, 
        children: [ 
         { title: "Sub-item 2.1" }, 
         { title: "Sub-item 2.2" } 
        ] 
       }, 
       { title: "Item 3" } 
      ] 
      }); 
     }); 

    </script> 
</head> 
<body> 
    <div id="tree"> 
    </div> 
</body> 
</html> 

順便說一句,如果你注意到了這一點,該文件是相當混亂,因爲它們是重構代碼,文檔是dynatree和fancytree的新約定的一半。所以期待更奇怪的東西,如: - )

+0

你是對的。但是用花式樹,我無法在每個子節點中調用渲染方法,因爲它在dyna樹中使用。它說parent.ul爲空:( – Billa 2013-02-21 04:43:17

+0

我不明白你的意思是「在每個孩子節點的渲染方法」... – zmo 2013-02-21 10:24:43

+0

我說這個。var childNodes = node.getChildren(); if(childNodes (已經被選擇)childNodes [i] .data。(已經被選擇){已經被選擇的子元素[i] .data.select; )(var i = 0; i Billa 2013-02-21 12:54:51

-1

是在SCRIPTPATH吧?你下載了「jquery.js,jquery-ui.custom.js,ui.fancytree.css和jquery.fancytree.js」嗎?

+0

是的。這是我提到的問題。我是否需要重命名複製到下載? – Billa 2013-02-14 19:55:19