zTree为JQuery的插件。
var setting = {
view: {
dblClickExpand: true,//双击展开
showLayer: false,
selectedMulti: false,//是否允许多选
showIcon: showIconForTree//显示节点小图标
},
data: {
simpleData: {
enable: true,
idKey: "id",
pIdKey: "pId",
rootPId: "0"
}
},
callback: {
beforeClick: beforeClick,
onClick: onClick
}
};
//加载当前项目的树形结构信息列表
function loadStructureInfoTreeJson(projectId) {
$.ajax({
type: "POST",
dataType: "json",
url: "../Tools/StructureModel.ashx",
data: { act: "LoadModelTreeByProjectid",
pid: projectId
},
success: function (data) {
if (data.length == 0) {
} else {
$.fn.zTree.init($("#tree"), setting, data);
var zTree = $.fn.zTree.getZTreeObj("tree");//获取ztree对象
var node = zTree.getNodeByParam('id', 1);//获取id为1的点
zTree.selectNode(node);//选择点
zTree.setting.callback.onClick(null, zTree.setting.treeId, node);//调用事件
}
},
error: function () {
alert("载入树形结构出现问题!");
}
});
}
function showIconForTree(treeId, treeNode) {
return treeNode.isParent;//如果是父节点就显示小图标
};
注:本文转载http://blog.csdn.net/a15937822658/article/details/17759995