6、/WebRoot/treeExampleStatic.jsp<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Showcase - UI Tag Example - Tree Example (Static)</title>
<s:head theme="ajax" debug="true" />
</head>
<body><!-- START SNIPPET: treeExampleStaticJsp --><script>
//是否创建叶子是绑定点击链接到/staticTreeSelectAction.action?
function treeNodeSelected(nodeId) {
dojo.io.bind({
url: "<s:url value='/staticTreeSelectAction.action'/>?nodeId="+nodeId,
load: function(type, data, evt) {
var divDisplay = dojo.byId("displayIt");
divDisplay.innerHTML=data;
},
mimeType: "text/html"
});
}; dojo.event.topic.subscribe("treeSelected", this, "treeNodeSelected");
</script>
<div style="float:left; margin-right: 50px;">
<s:tree label="parent" id="parentId" theme="ajax" templateCssPath="/struts/tree.css"
showRootGrid="true" showGrid="true" treeSelectedTopic="treeSelected">
<s:treenode theme="ajax" label="child1" id="child1Id">
<s:treenode theme="ajax" label="<a href='index.jsp'>grandchild1</a>" id="grandchild1Id"/>
<s:treenode theme="ajax" label="grandchild2" id="grandchild2Id"/>
<s:treenode theme="ajax" label="grandchild3" id="grandchild3Id"/>
</s:treenode>
<s:treenode theme="ajax" label="child2" id="child2Id"/>
<s:treenode theme="ajax" label="child3" id="child3Id"/>
<s:treenode theme="ajax" label="child4" id="child4Id"/>
<s:treenode theme="ajax" label="child5" id="child5Id">
<s:treenode theme="ajax" label="gChild1" id="gChild1Id"/>
<s:treenode theme="ajax" label="gChild2" id="gChild2Id"/>
</s:treenode>
</s:tree>
</div>
<div id="displayIt">
Please click on any node on the tree.
</div><!-- END SNIPPET: treeExampleStaticJsp --></body>
</html>7、/WebRoot/treeExampleDynamic.jsp
<%@taglib prefix="s" uri="/struts-tags" %><html>
<head>
<title>Showcase - UI Tag Example - Tree Example (Dynamic)</title>
<s:head theme="ajax" debug="true" />
</head>
<body><!-- START SNIPPET: treeExampleDynamicJsp --><script>
function treeNodeSelected(nodeId) {
dojo.io.bind({
url: "<s:url value='dynamicTreeSelectAction.action' />?nodeId="+nodeId,
load: function(type, data, evt) {
var displayDiv = dojo.byId("displayId");
displayDiv.innerHTML = data;
},
mimeType: "text/html"
});
}; dojo.event.topic.subscribe("treeSelected", this, "treeNodeSelected");
</script><div style="float:left; margin-right: 50px;">
<s:tree
theme="ajax"
rootNode="%{treeRootNode}"
childCollectionProperty="children"
nodeIdProperty="id"
nodeTitleProperty="name"
treeSelectedTopic="treeSelected">
</s:tree>
</div><div id="displayId">
Please click on any of the tree nodes.
</div><!-- END SNIPPET: treeExampleDynamicJsp --></body>
</html>8、dynamicTreeSelect.jsp
<%@taglib prefix="s" uri="/struts-tags" %>Id:<s:property value="%{nodeId}" /><br/>
Name:<s:property value="%{nodeName}" /><br/>
function treeNodeSelected(arg) {
得到ID 是arg.source.widgetId;
这里实现连接
}
dojo.addOnLoad(function() {
var s = dojo.widget.byId('parentId').selector;
dojo.event.connect(s, 'select', 'treeNodeSelected');
});
树标签
<div style="float: left; width: 300px;">
<s:tree id="parentId"
theme="ajax"
rootNode="root"
childCollectionProperty="childrenArray"
nodeIdProperty="ktid"
nodeTitleProperty="ktname"
treeSelectedTopic="treeSelected">
</s:tree>
</div>BS 一下stuts2的树标签 ,很恶心