javascript – 具有本地数组数据的jQuery花式树

我正在尝试使用本地数组数据实现jQuery FancyTree http://wwwendt.de/tech/fancytree/demo/

https://code.google.com/p/fancytree/开始

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

Even i copied the jQuery, UI versions of the file they using in a demo
site. Still nothing works

<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>

解决方法:

我注意到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的新约定的一半.所以期待更多奇怪的东西:-)

上一篇:TreeView拖动并存入数据库(可判断拖动)


下一篇:c# – 仅在儿童节点中的复选框?