我有2个下拉选择基于选择即时获取json数据来显示树但是我不能在选择中显示树但是如果我运行特定的jsp即可获得树中的任何选择。但是我无法追加子节点。每件事都来自数据库。基于数据必须显示树,并且每次都在渲染相同的树。
它看起来像 -root node
|__NodeA
|__NodeB
|__NodeC
如果我选择NodeA相同的根节点 - nodeA - NodeB - NodeC 来了。
基本上我需要选择节点子应该追加下一个。 请有人帮助我。
结果应该是
root node
|__NodeA
|__NodeB
|__NodeC
如果我选择nodeA
root node
|__NodeA
|--child1
|--child2
|__NodeB
|__NodeC
像那样。
这是我的jsp ..
<head>
<sj:head jqueryui="true" jquerytheme="showcase" debug="false"/>
</head>
<script>
$.subscribe('treeClicked', function(event, data) {
var item = event.originalEvent.data.rslt.obj;
alert('Clicked ID : ' + item.attr("id"));
});
function gettree()
{
document.forms.tree.action="echo.action";
document.forms.tree.submit();
}
</script>
<body>
<s:form name="tree">
<s:label name="Sataion">Station</s:label>
<s:select list="stationMap" name="stationId" id="stationid" headerValue=-- Select--" headerKey="-1" />
<s:submit value="Submit" onclick="gettree();" />
enter code here>
<s:url action="echo" id="echo"/>
<s:url action="childNodeexecute" id="childNodeexecute"></s:url>
<sjt:tree
id="echo"
href="%{echo}"
jstreetheme = "apple"
rootNode="nodes"
onClickTopics="treeClicked"
nodeHrefParamName="childNodeexecute"
childCollectionProperty="children"
nodeIdProperty="stationId"
nodeHref="%{childNodeexecute}"
/>
</s:form>
</body>
我的动作类
public String execute(){
Map session = ActionContext.getContext().getSession();
//session.get("stationMap");
setStationMap((Map<Integer, String>) session.get("stationMap"));
AppRejectDao dao = new AppRejectDao();
setTest("hello");
List<DistributonNodesnew> listvalues =dao.selectediddetails(getStationId());
session.put("listvalues", listvalues);
for (DistributonNodesnew distributonNodesnew : listvalues) {
TreeNode nodeA = new TreeNode();
nodeA.setId(distributonNodesnew.getDistributionNodeID());
nodeA.setTitle(distributonNodesnew.getDistributionNodeName());
nodes.add(nodeA);
}
return SUCCESS; }
public String childNodeexecute()
{
Map session = ActionContext.getContext().getSession();
List<DistributonNodesnew> listvalues;
TreeNode nodeA = new TreeNode();
AppRejectDao dao = new AppRejectDao();
listvalues = (List<DistributonNodesnew>) session.get("listvalues");
setStationMap((Map<Integer, String>) session.get("stationMap"));
for (DistributonNodesnew distributonNodesnew : listvalues) {
if(distributonNodesnew.getDistributionNodeID() == null ? nodeA.getId() == null : distributonNodesnew.getDistributionNodeID().equals(nodeA.getId()))
{
List<DistributonNodesnew> listvaluesnew =dao.selectediddetails(Integer.parseInt(nodeA.getId()));
for (DistributonNodesnew distributonNodesnew1 : listvaluesnew) {
TreeNode childnode = new TreeNode();
nodeA.setChildren(new LinkedList<TreeNode>());
childnode.setId(distributonNodesnew1.getDistributionNodeID());
childnode.setTitle(distributonNodesnew1.getDistributionNodeName());
nodeA.getChildren().add(childnode);
nodes.add(nodeA);
}
}
}
return SUCCESS;
}
和我的struts.xml
/jsp/AppRejstruts2/tree.jsp
<action name="echo" class="com.myapp.struts2.Apprej.TreeDynamicAction" >
<result name="success" type="json" >
<param name="root">nodes</param>/jsp/AppRejstruts2/tree.jsp</result>
</action>
<action name="childNodeexecute" class="com.myapp.struts2.Apprej.TreeDynamicAction" method="childNodeexecute">
<result name="success" type="json" >
<param name="root">nodes</param>/jsp/AppRejstruts2/tree.jsp</result>
</action>