JStree CheckBox 默认选中 jstree checkbox checked onload

来源:互联网 发布:windows升级要多少钱 编辑:程序博客网 时间:2024/05/29 14:50

红色部分:也可以使用注释的那行  


                             $("#jstree_demo")

                               .jstree({                                 

                                   "core" : {

                                       "animation" : 0,

                                       "check_callback" : true,

                                       'force_text' : true,

                                       "themes" : { "stripes" : true },

                               // so that create works

                                   "check_callback" : true,

                                   'data' : function (obj, callback) {

                                                var jsonstr="[]";

                                                var jsonarray = eval('('+jsonstr+')');

                                                

                                                $.ajax({

                                                    type: "POST",

                                                    url:url,

                                                    dataType:"json",

                                                    async: false,

                                                    success:function(result) {

                                            

                                                     

                                                        var arrays= result;

                                              

                                                        for(var i=0 ; i<arrays.length; i++){

                                                        console.log(Object.getOwnPropertyNames(arrays[i]).sort());

                                                            var arr = {

                                                                    "id":arrays[i].id,

                                                                    "parent":arrays[i].pid==""?"#":arrays[i].pid,

                                                                    "text":arrays[i].name,

                                                                    "type":arrays[i].iconSkin,

                                                                    "state": {"opened" : true,"selected":true}

                                                                    //"state": {"selected":true}

                                                            }

                                                            jsonarray.push(arr);

                                                        }

                                                    }


                                                });

                                                

                                                callback.call(this, jsonarray);

                                            }

                                        },

              

                                        "plugins" : [ "search""state""types""wholerow","checkbox" ]

                                    });