0

我需要用户 jquery jstree cookies 插件。我的脚本如下:

这是使用 cookie 插件的脚本:

$(document).ready(function(){


     $("#tree").jstree({  



         "xml_data" : {  

             "ajax" : {  

                 "url" : "jstree.xml" 

             },  

             "xsl" : "nest"


         },  
         "themes" : {  

             "theme" : "classic",  

            "dots" : true,  

             "icons" : true 

         },  
         "ui": {
         "save_selected" : false,
         },

        "search" : {  

                 "case_insensitive" : true,  

                 "ajax" : {  

                     "url" : "jstree.xml" 

                 }  

             }, 

        "cookies" : { 
                    "cookie_options" : {
                                    "path": "C:/Users/docs"

                                    } 
                }, 


              "plugins" : ["themes", "xml_data", "ui","types", "search"] 


    }).bind("select_node.jstree", function (event, data) {

        $("#tree").jstree("toggle_node", data.rslt.obj);

网页错误详情

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
Timestamp: Mon, 25 Feb 2013 19:46:57 UTC


Message: Exception thrown and not caught
Line: 2053
Char: 42
Code: 0
jquery.jstree.js

这是它抱怨的那一行:

if(typeof $.cookie === "undefined") { throw "jsTree cookie: jQuery cookie plugin not included."; }

cookies 插件是 jstree.js 文件的一部分,还是有一个单独的 js 用于 cookies 插件?如果有不同的 cookies.js 文件,我在哪里可以得到这个文件?任何帮助是极大的赞赏。

4

1 回答 1

2

jsTree 插件需要jQuery cookie 插件才能使用 cookie。确保在加载 jsTree 之前加载它。


有效的示例代码:

<html>
<head>
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script src="/path/to/jquery.cookie.js"></script>
  <script src="/path/to/jstree/jquery.jstree.js"></script>
  <script>
$(function() {
   $("#tree").jstree({  
     "cookies" : { 
                    "cookie_options" : {
                                    path: 'c:/Users/hceylan1/docs'
                                    } 
                },
                "xml_data" : {
            "data" : "" +
"<root>" +
    "<item id='node_1'>" +
        "<content><name>Root node 1</name></content>" +
    "</item>" +
    "<item>" +
        "<content><name>Root node 2</name></content>" +
    "</item>" +
    "<item parent_id='node_1'>" +
        "<content><name>Child node</name></content>" +
    "</item>" +
"</root>"
        },

    "plugins" : ["themes", "xml_data", "ui","types", "search", "cookies"] 
    }).bind("select_node.jstree", function (event, data) {

        $("#tree").jstree("toggle_node", data.rslt.obj);
    });
});
  </script>
</head>
<body>
<div id="tree">
</div>
</body>
</html>
于 2013-02-25T19:58:08.540 回答