带有本地数组数据的jQuery花式树

时间:2013-02-14 15:16:08

标签: javascript jquery jquery-ui jquery-plugins treeview

我正在尝试使用本地数组数据

实现jQuery FancyTree http://wwwendt.de/tech/fancytree/demo/

摘自https://code.google.com/p/fancytree/

这是代码。但它不起作用,没有脚本错误。但树是空的!!!

  

甚至我复制了他们在演示中使用的文件的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>

2 个答案:

答案 0 :(得分: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的新约定的一半。所以期待更多奇怪的东西: - )

答案 1 :(得分:-1)

是Scriptpath吗?

你下载“jquery.js,jquery-ui.custom.js,ui.fancytree.css和jquery.fancytree.js”吗?