Jstree 使用CheckBox插件 選中父節點時被禁用的子節點也會選中問題

問題描述:javascript

最近用jstree遇到一個問題,使用CheckBox插件時,當父節點選中時,被禁用的子節點也會選中以下java

 

解決方案:node

一、  將jstree升級到最新的版本,v3.3.4及以上就能夠spa

二、 修改checkbox插件配置,cascade_to_disabled設置爲false(注:須要將配置腳本放jstree.min.js的後面)插件

<script src="./../../dist/jstree.min.js"></script>
<script>
$.jstree.defaults.checkbox = {
           visible: true,
           three_state: true,
           whole_node: true,
           keep_selected_style: true,
           cascade: '',
           tie_selection: true,
           /**
            * This setting controls if cascading down affects disabled checkboxes
            * @name $.jstree.defaults.checkbox.cascade_to_disabled
            * @plugin checkbox
            */
           cascade_to_disabled : false,
           cascade_to_hidden : true
};


$('#data').jstree({
        'core' : {
            'data' : [
                { "text" : "Root node", "children" : [
                        { "text" : "Child node 1", "state": { "disabled": true } },
                        { "text" : "Child node 2" },
                        { "text" : "Child node 3" },
                        { "text" : "Child node 4" },
                        { "text" : "Child node 5" },
                        { "text" : "Child node 6" }
                ]}
            ]
        }
        ,"plugins" : [ "checkbox" ]
    });
</script>

修改後當選中父節點時,子節點會跳過禁用子節點以下:blog

 

相關文章
相關標籤/搜索