<html>
<head>
<link rel="StyleSheet" href="include/dtree/dtree.css" type="text/css" />
<script type="text/javascript" src="include/dtree/dtree.js"></script>
</head>
<body>
<?php
include_once("./class.config.php");
$Result = $db->SelectSQL("select * from dept order by ParentDeptCode");
while($temp = $db->Fetch($Result))
{
$Rs[]=$temp;
}
//如果PHP版本为5.2.0以上,直接用内置JSON函数
//否则就使用第3方的JSON类库
$str=json_encode($Rs);
/*
下面是调用js的方法
注意:下面的写法是错误的:
//echo '<script type="text/javascript">Test("'.$str.'");</script>';
echo '<script type="text/javascript">Test('.$str.');</script>';
*/
?>
<script type="text/javascript">
<!--
d = new dTree('d');
for(i=0;i<r.length;i++)
{
d.add(Number(r[i].DeptCode),Number(r[i].ParentDeptCode),r[i].DeptName,"DeptCode="+r[i].DeptCode);
//d.add(i,-1+i,r[i].DeptName);
}
document.write(d);
</script>
</body>
</html>
在这里要注意,dtree.js的根节点索引为-1;