刚开始做的时候一直没找到要领,各种百度和google都没找到解决的办法,不过方法是对的,使用setXMLAutoLoading,其实你只要知道每当展开一个节点会自动传递id的内容,这样就好做了。
dhtmlx提供的例子:
tree = new dhtmlXTreeObject("treeboxbox_tree", "100%", "100%", 0);
tree.setSkin('dhx_skyblue');
tree.setImagePath("../../codebase/imgs/csh_bluebooks/");
tree.setXMLAutoLoading("php/xml.php");
tree.loadXML("php/xml.php?id=0");
xml.php内容:
<?php
error_reporting(E_ALL ^ E_NOTICE);
header("Content-type:text/xml"); print("<?xml version=\"1.0\"?>");
if (isset($_GET["id"]))
$url_var=$_GET["id"];
else
$url_var=0;
print("<tree id='".$url_var."'>");
for ($inta=0; $inta<4; $inta++)
print("<item child='1' id='".$url_var."_".$inta."' text='Item ".$url_var."-".$inta."'><userdata name='ud_block'>ud_data</userdata></item>");
print("</tree>");
?>
xml.php的作用,这个可以是一个xml文件,拼上头和尾,然后根据id做个判断,然后各种拼写内容就可以了。
tree.loadxml里id可以写也可以不写,在xml里做个判断就可以。