javascript - JsTree 多树cookie

标签 javascript jquery jstree

大家好,我使用 jstree,我在同一个页面中有多个树。我有两个问题:

1) 我想要 cookie 来区分每棵树中哪些节点是打开的。我尝试使用前缀来实现此功能,但不幸的是:

"cookies" : { "cookie_options" : { "prefix" : "home" } },

不起作用,因为只有最后打开的节点在刷新后重新打开。

2) 我不希望能够创建新的根节点。我只想能够创建文件或将文件传输到我的根目录中。

我正在尝试使用:

"types" : {
            "types" : {
                // The default type
                "default" : {
                    "valid_children" : "none",
                    "icon" : {
                        "image" : "./file.png"
                    }
                },
                // The `folder` type
                "folder" : {
                    "valid_children" : [ "default", "folder", "file" ],
                    "icon" : {
                        "image" : "./folder.png"
                    }
                },
                // The `drive` nodes 
                "drive" : {
                    // can have files and folders inside, but NOT other `drive` nodes
                    "valid_children" : [ "default", "folder" ],
                    "icon" : {
                        "image" : "./root.png"
                    },
                    // those prevent the functions with the same name to be used on `drive` nodes
                    // internally the `before` event is used
                    "start_drag" : false,
                    "move_node" : false,
                    "delete_node" : false,
                    "remove" : false
                }
            }
        },

但我仍然可以将文件发布到我的根目录中。我应该再创建一个 <li> 吗?没有rel=drive在根目录之上?

谢谢。

最佳答案

多树cookie的解决方法:

.
.
"cookies": {
  "save_selected": "node_selected_" + tree_id
  "save_opened": "node_opened_" + tree_id
},
.
.

没有“前缀”这样的选项。 “save_selected”和“save_opened”采用字符串或 false。通过提供不同的 tree_id,您可以有效地为每棵树使用不同的 cookie。

关于javascript - JsTree 多树cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9102696/

相关文章:

javascript - Gnome-Shell 扩展,观察 GSettings 的变化吗?

javascript - 确定文件是否已导入或未在 react 中导入

jquery - 有多个 div 时如何正确应用 z-index

c# - .net 中的 jquery+jstree - web 服务响应格式?

jquery - 取消选择选定的树节点 JStree - jQuery

javascript - jQuery 仅替换新的选择框,而不替换之前的选择框

javascript - 在 Controller 中发出 HTTP 请求 - sails.js

javascript - 如何使用 jQuery 打印文档中的表格内容?

javascript - JSON 值显示 NaN

xml - 带有超棒字体的 jsTree 树中的节点图标