Ztree 引入外部json

Ztree 是个不错的 树控件,引用包什么得我就不说了。直接上代码了。

一 ,HTML

<div id="treeDemo" class="ztree"></div>

二,JS

var setting = {};
            
            var zNodes = "json/member.json";
            $().ready(function() {
                $.ajax({
                    type: 'get',
                    url: zNodes,
                    dataType: 'json',
                    success: function(data) {
                        $.fn.zTree.init($("#treeDemo"), setting, data);
                    },
                    error: function(data) {
                        alert("错误");
                    }
                });
            });

三,JSON

[{
    "name": "学员管理",
    "open": true,
    "children": [{
            "name": "大一",
            "children": [{
                    "name": "张三",
                    "img": "img/psd.png"
                }, {
                    "name": "小赵",
                    "img": "img/psa.png"
                }, {
                    "name": "凡小芬",
                    "img": "img/psc.png"
                }]
        }]
}]


你可能感兴趣的:(Ztree 引入外部json)