基础:
<link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../../../js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
<div id="tree" class="widget-main">
<ul id="treeDemo" class="ztree"></ul>
</div>
function showIconForTree(treeId, treeNode) {
return ((9==treeNode.kind || 0==treeNode.kind)?true:false);//根据条件
//return treeNode.isParent; //根据是否为父节点
}
var setting =
{
15 view: {
16 showIcon: showIconForTree //图标
17 },
18 data: {
19 simpleData: {
20 enable: true
21 },
22 key:{
23 name: "name",
24 }
25 },
26 callback: {
27 onClick: zTreeOnClick //回调单机事件
28 }
};
$.fn.zTree.init($("#treeDemo "), setting, data);
var zTree = $.fn.zTree.getZTreeObj("treeDemo ");//获取树
var root = zTree.getNodeByParam('id', '0');//获取id为0d的点
zTree.expandNode(root, true, false, true);//展开选中节点
zTree.selectNode(root);//选择节点
zTree.setting.callback.onClick(null, zTree.setting.treeId, root);//调用事件