JSTree - 禁用加载时自动选择子项

时间:2014-08-26 15:19:40

标签: javascript php jquery jstree

我需要在加载时禁用所有孩子的自动选择。如果我将带有selected参数的父节点设置为true,它将选择其所有子节点,但我想只选择父节点。

$('#tree_groups').jstree({
        'plugins': ["wholerow", "checkbox", "types"],
        'core': {
            'data': [{
                "id": "0-14089749041",
                "text": "Sport",
                "state": {
                    "selected": true,
                },
                "children": [{
                "id": "14089749041-14089751330",
                "text": "Pallacanestro",},
                {"id": "14089749041-14089751110",
                "text": "Tennis",},
            ]},
        "types" : {
            "default" : {
                "icon" : "fa fa-group icon-state-warning icon-lg"
            },
            "file" : {
                "icon" : "fa fa-file icon-state-warning icon-lg"
            }
        }
    });

由于

1 个答案:

答案 0 :(得分:4)

我自己找到了答案,我只是将复选框插件的three_state设置为false。

$('#tree_groups').jstree({
    'plugins': ["wholerow", "checkbox", "types"],
    'core': {
        'data': [{
            "id": "0-14089749041",
            "text": "Sport",
            "state": {
                "selected": true,
            },
            "children": [{
            "id": "14089749041-14089751330",
            "text": "Pallacanestro",},
            {"id": "14089749041-14089751110",
            "text": "Tennis",},
        ]},
    "checkbox" : {
            "three_state" : false,
        },
    "types" : {
        "default" : {
            "icon" : "fa fa-group icon-state-warning icon-lg"
        },
        "file" : {
            "icon" : "fa fa-file icon-state-warning icon-lg"
        }
    }
});