jstree基础知识的新手

时间:2014-06-18 15:35:28

标签: javascript jstree

我最近开始使用jstree进行项目。我查看了jstree网站上的文档,并提出了一个非常简单的树:

<div id="jstree_test"></div>
<script>
$(function () {

$('#jstree_test').jstree({
    core: {
        data: [
                {
                    id: 'parent1',
                    parent: '#',
                    text: 'p1'
                },
                {
                    id: 'child1',
                    parent: 'parent1',
                    text: 'c1'
                },
                {
                    id: 'child2',
                    parent: 'parent1',
                    text: 'c2'
                },
                {
                    id: 'child3',
                    parent: 'parent1',
                    text: 'c3'
                }
        ]
    }
});

});             
</script>

当我运行此代码时,我得到的只是'p1',其子弹点与自身相关联。我想要的代码只是p1,有三个孩子c1,c2和c3。任何帮助将不胜感激。

感谢您的时间

1 个答案:

答案 0 :(得分:0)

将state属性添加到对象中的特定节点。

$('#jstree_test').jstree({
    core: {
        data: [
            {
                id: 'parent1',
                parent: '#',
                text: 'p1',
                'state' : {
                       'opened' : true,
                       'selected' : true
                 }
            },
            {
                id: 'child1',
                parent: 'parent1',
                text: 'c1'
            },
            {
                id: 'child2',
                parent: 'parent1',
                text: 'c2'
            },
            {
                id: 'child3',
                parent: 'parent1',
                text: 'c3'
            }
    ]
}
});

在jsbin中给出一个演示 - DEMO