如果数据没有在核心中定义,jstree不会保存状态?

时间:2016-02-17 19:21:56

标签: 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
            }

这两种影响状态插件的方法有区别吗? 谢谢!

1 个答案:

答案 0 :(得分:3)

实际上,它只是有效。

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

签出codepen,尝试添加新节点或展开/折叠节点,然后重新加载页面。国家将被铭记。