html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xml_tree</title>
</head>
<body>
<div id="tree_box" style="background-color:#CCCCCC;height:500px;width:150px"></div>
</body>
<script language="javascript" src="scripts/jsframework.js"></script>
<script language="javascript">
Using("System.Web.UI.WebControls.MzTreeView");
var tree = new MzTreeView();
var data = {};
tree.setIconPath("scripts/system/_resource/mztreeview"); //可用相对路径
data["-1_0"]="text:所有商品;icon:addrbook;XMLData:sort.xml";
tree.dataSource=data;
tree.autoSort=false;
tree.canOperate=true;
document.getElementById("tree_box").innerHTML=tree.render(true);
tree.expandLevel(1);
</script>
</html>
/*注意:js代码放<div id="tree_box".....>后面,或者js写在加载后执行的代码中*/
sort.xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<nodes>
<fsort text="家具">
<sort_name text="沙发"></sort_name>
<sort_name text="衣柜"></sort_name>
<sort_name text="桌椅"></sort_name>
<sort_name text="风扇"></sort_name>
</fsort>
<fsort text="生活用品">
<sort_name text="台灯"></sort_name>
<sort_name text="挂钟/闹钟"></sort_name>
<sort_name text="雨伞/雨衣"></sort_name>
<sort_name text="杯子"></sort_name>
</fsort>
</nodes>
附:xml文件可以通过AJAX获取服务器数据......(这我就不多说了)
显示结果: