<!-- Json 循环列出树形菜单 注意点:tree.nodes[]中键不可加引号 -->
<script type="text/javascript">
var tree = new MzTreeView("tree");
tree.icons["property"] = "property.gif";
tree.icons["css"] = "collection.gif";
tree.icons["event"] = "collection.gif";
tree.icons["book"] = "book.gif";
tree.iconsExpand["book"] = "bookopen.gif";
tree.setIconPath("/images/treeview/"); //展开时对应的图片的存放路径
tree.nodes["0_1"] = "text:世界;url:/Contract/index";
tree.nodes["1_2"] = "text:中国;url:/Contract/index";
tree.nodes["1_3"] = "text:美国;url:/Contract/index";
tree.nodes["2_5"] = "text:北京;url:/Contract/index";
tree.nodes["2_6"] = "text:天津;url:/Contract/index";
tree.nodes["2_7"] = "text:上海;url:/Contract/index";
tree.nodes["2_8"] = "text:河北;url:/Contract/index";
tree.nodes["3_9"] = "text:洛杉矶;url:/Contract/index";
tree.nodes["3_10"] = "text:华盛顿;url:/Contract/index";
tree.nodes["5_11"] = "text:海淀;url:/Contract/index";
tree.nodes["5_12"] = "text:朝阳;url:/Contract/index";
tree.nodes["8_13"] = "text:石家庄;url:/Contract/index";
tree.nodes["8_14"] = "text:邯郸;url:/Contract/index";
//var treeList = <?php echo $tree; ?>;
//for(var key in treeList){
// tree.nodes[treeList[key].concate.parent_id + "_" + treeList[key].concate.id] = "text:" + treeList[key].concate.caption + ";url:http://www.baidu.com;target:_blank";
//}
document.write(tree.toString());
</script>
注意:注意:当用循环Json时,需要注意到tree.nodes[""]中的""是不可用的,否则可能会显示不了!当写数据时,可以这样写:tree.nodes["0_1"] = "text:AAA;url:bbb";但当循环时,例:tree.nodes["'" + treeList[key].concate.parent_id + "_" + treeList[key].concate.id + "'"] = "text:" + treeList[key].concate.caption + ";url:http://www.baidu.com;target:_blank";这种不可取。"'"不能写。
最后效果:如下图