感觉上编程创建树结构要比使用标签创建更加容易,不知道各位想法如何??
例子如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dojo Tree Widget Test (dynamic node creation)</title>
<script type="text/javascript">
var djConfig = {isDebug: true,debugAtAllCosts: true };
</script>
<!-- 引入dojo库-->
<script type="text/javascript" src="../../../dojo.js"></script>
<script type="text/javascript">
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.TreeV3");
dojo.require("dojo.widget.TreeNodeV3");
dojo.require("dojo.widget.TreeBasicControllerV3");
dojo.hostenv.writeIncludes();
</script>
<script type="text/javascript">
<!-- 加载完叶面后执行-->
dojo.addOnLoad(function(){
//创建controller,tree
var controller = dojo.widget.createWidget("TreeBasicControllerV3");
var tree = dojo.widget.createWidget("TreeV3",{listeners:[controller.widgetId]});
//这里直接加到body上,可以指定任一个容器
document.body.appendChild(tree.domNode);
var rootNode = dojo.widget.createWidget("TreeNodeV3",{title: "Root Node",tree: tree.widgetId});
//创建根节点
tree.addChild(rootNode);
var node1 = dojo.widget.createWidget("TreeNodeV3",{title: "Node 1",tree: tree.widgetId});
//增加子节点
rootNode.addChild(node1);
//给node1增加子节点
var node2 = dojo.widget.createWidget("TreeNodeV3",{title: "Node 1.2",tree: tree.widgetId});
node1.addChild(node2,null,"after");
});
</script>
</head>
<body>
</body></html>
原文链接:https://www.f2er.com/dojo/291987.html