如果数据未在核心中定义,则 JSTREE 不会保存状态



我有一个使用 jstree 的应用程序。在这个应用程序中,我将核心的"数据"部分设置为空数组,如下所示:

$("#jstree")
    .jstree({
        "core": {
            "data": [],
            "check_callback" : true,
            "themes": {
                "theme": "default",
                "icons": false
            }
        },
        "plugins": [ "state" ]
    })

当新数据发送到浏览器时,我正在使用 jstree.create_node() 以编程方式将新节点添加到树中。当我刷新页面时,即使我正在使用状态插件,树也不会保持状态。但是,如果我将核心中的data字段设置为实际的 JSON 对象,它将按照state插件中的说明工作:

 "core": {
            "data":[{"id":"a", "parent":"#", "text":"nodeA"},{"id":"b", "parent":"a", "text":"nodeB"}],
            "check_callback" : true,
            "themes": {
                "theme": "default",
                "icons": false
            }

影响状态插件的两种方式之间有区别吗?谢谢!

实际上,它只是有效。

jstree({
    "core": {
        "data": [
          {"id":"a", "parent":"#", "text":"nodeA"},{"id":"b", "parent":"a", "text":"nodeB"}
        ],
        "check_callback" : true,
        "themes": {
            "theme": "default",
            "icons": false
        }
    },
    "plugins": [ "state" ]
})

签出代码笔,尝试添加新节点或展开/折叠节点,然后重新加载页面。状态将被记住。

最新更新