ztree树默认根据ID默认选中该条数据

function getZtree() {
    var setting = {
        view: {
            expandSpeed: 100,
            selectedMulti: true,
            showLine: true, // 是否显示节点间的连线
            fontCss: {},
        },
        async: {
            type: "GET",
            enable: true,
            url: getRootPath() + "/upload/queryByZtree?speciaity=" + $("#speciaity").val(), // Ajax 获取数据的 URL 地址
            autoParam: ["id=id"],
            dataFilter: filter
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pid",
                rootPId: '0'
            },
            key: {
                name: "name"
            }
        },
        callback: {
            onClick: selectOnClick,
            // 节点被点击时调用的方法
            onAsyncSuccess: onAsyncSuccess
        }
    };
    function onAsyncSuccess(event, treeId, treeNode, msg) {
        var f = $("#add_fileid_id").val();//所选的ID   例如 "12589"
        var treeObj = $.fn.zTree.getZTreeObj(treeId);//ztree树的ID
        var node = treeObj.getNodeByParam("id", f);//根据ID找到该节点
        treeObj.selectNode(node);//根据该节点选中
    };
   

你可能感兴趣的:(目录树)