ZTree 原生树

创建树方法:

$.fn.zTree.init($('#dsReportTree'), viewModel.treeSetting, treeData);
方法一:

treeSetting: {
                    data: {
                        simpleData: {
                          enable: true//必须要标明是简单数据类型
                        }
                    },
                    callback: { }
                },
//treeData固定字段名 id name pId
for (i = 0, length = result.data.length; i < length; i++) {
                                treeData.push({
                                  id: result.data[i].REPORT_CODE,
                                  name: result.data[i].REPORT_TEXT,
                                  pId: result.data[i].PAR_CODE,
                                  REPORT_NAME:result.data[i].REPORT_NAME
                                });
                            }
                       treeData.push({
                          id: "1000",
                          name: "打印报表",
                          pId: null,
                        });

方法二

var treeSetting= {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "pId",
            rootPId: 0
        }
    }
};
var treeData= [
    {"id":1, "pId":0, "name":"test1"},
    {"id":11, "pId":1, "name":"test11"},
    {"id":12, "pId":1, "name":"test12"},
    {"id":111, "pId":11, "name":"test111"}
];

你可能感兴趣的:(ZTree 原生树)