3

我正在尝试使用 jstree 从 xml 文件构建树。我遵循了文档,看起来它不起作用。这是我的代码:

<html>
<head>
    <title>Demo</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="C:\Users\jstree\jstree_pre1.0_fix_1\jquery.jstree.js"></script>
    <Script Language="JavaScript">
  $(function () {  

     $("#demo2").jstree({   

         "xml_data" : {  

             "ajax" : {  

                 "url" : "books.xml" 

             },  

             "xsl" : "nest" 

         },  

         "plugins" : [ "themes", "xml_data" ]  

     });  
     }); 

</Script>

</head>
<body>

</body>

4

4 回答 4

2

The XML is not formatted in a way that jsTree can include it.

http://www.jstree.com/documentation/xml_data

Two types of XML structures are supported - flat and nested:

<!-- FLAT -->
<root>
    <item id="root_1" parent_id="0" state="closed">
        <content>
            <name><![CDATA[Node 1]]></name>
        </content>
    </item>
    <item id="node_2" parent_id="root_1">
        <content>
            <name><![CDATA[Node 2]]></name>
        </content>
    </item>
</root>

<!-- NESTED -->
<root>
    <item id="xml_1">
        <content><name><![CDATA[Root node 1]]></name></content>
        <item id="xml_2">
            <content><name><![CDATA[Child node 1]]></name></content>
        </item>
    </item>
</root>

An alternative is to bring the XML document in and convert it into JSON, then transform it into a valid JSON or HTML data format.

于 2012-04-18T23:35:01.393 回答
1

看起来容器(#demo2)不见了。尝试<div id='demo2'></div>body标签下添加。

还要确保正确加载 jstree.js 文件。

于 2012-04-18T10:02:47.050 回答
0

给出一个相对路径而不是"url" : "books.xml"。将其替换为当前路径,例如"url" : "../Content/Xml/books.xml"。那可能行得通。

问候, 阿姆鲁萨

于 2014-06-25T09:32:24.200 回答
0

对于称为“语言”的脚本没有这样的属性(可能有,但已弃用)。

将您的代码放在脚本标签中,如下面的代码,然后重试

<script type="text/javascript">
    //Your Code Here
</script>
于 2012-04-13T21:08:37.797 回答