求助递归方法的解决??

hujunw520 2008-04-15 04:02:03
我用递归方法写出一个树状结构,不过是嵌套一层。
比如说:
中国
广东省
湖南省
安徽省
下面,我想要的结果是:
中国
广东省
广州市
茂名市
……
我该怎么写???如果说用纯JS又该怎么去写???
我的e-mail地址:hujunw@163.com
...全文
111 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wensheng_zh2007 2008-04-16
  • 打赏
  • 举报
回复
推荐JTree
hujunw520 2008-04-16
  • 打赏
  • 举报
回复
呵呵~!谢谢了!
yuanjun_xf 2008-04-16
  • 打赏
  • 举报
回复
顶7楼的!!
AwL_1124 2008-04-16
  • 打赏
  • 举报
回复
学习····
[Quote=引用 7 楼 Dan1980 的回复:]
楼主要JS的么?超级简单,比JAVA写得简单得多,呵呵。

HTML code<html>
<head>
<script type="text/javascript">

function Tree(name, children) {
this.name = name || "";
this.children = children || [];

this.appendChild = function(child) {
this.children.push(child);
}

this.toString = function() {
var result = "";
result += "<div>|- " + thi…
[/Quote]
南南北北 2008-04-16
  • 打赏
  • 举报
回复
学习。。。
Dan1980 2008-04-16
  • 打赏
  • 举报
回复
楼主要JS的么?超级简单,比JAVA写得简单得多,呵呵。
<html>
<head>
<script type="text/javascript">

function Tree(name, children) {
this.name = name || "";
this.children = children || [];

this.appendChild = function(child) {
this.children.push(child);
}

this.toString = function() {
var result = "";
result += "<div>|- " + this.name + "</div>";
for (var i = 0; i < this.children.length; i++)
result += "<div style='margin-left: 1em'>" + this.children[i] + "</div>";
return result;
}
}

var tree = new Tree("中国");
tree.appendChild(new Tree("广东省", [new Tree("广州市"), new Tree("茂名市")]));
</script>
</head>
<body onload="document.getElementById('tree').innerHTML = tree">
<div id="tree"></div>
</body>
</html>
aking21alinjuju 2008-04-15
  • 打赏
  • 举报
回复
等待高手
南南北北 2008-04-15
  • 打赏
  • 举报
回复
推荐dtree
hujunw520 2008-04-15
  • 打赏
  • 举报
回复
是的~~
比如
点击中国就出现广东省在点击广东省有出现广东省的所有城市
cyj18 2008-04-15
  • 打赏
  • 举报
回复
你是想怎么做...存在数据库里读还是放到XML里读?或者有更好的办法?
kevinchj 2008-04-15
  • 打赏
  • 举报
回复
什么递归……是不是说你想要级联菜单?

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧