递归例子(Javascript)

目标:读取一个层次架构构树。


主程序:

var treeSource=data.treeNode;
var treeNode = new Array();
if(treeSource){
	// 递归获取子node
	treeNode.push({name:treeSource.name, value:treeSource.value, children:$biosMain.getTreeNode(treeSource.children), 
		nodeType:treeSource.nodeType, itemStyle: {normal: {color: $biosMain.getItemStyle(treeSource.nodeType)}}});

data.treeNode是一个java对象,见: 递归例子(Java) http://blog.csdn.net/textboy/article/details/46544115

FileOrganizationNode treeNode = new FileOrganizationNode();

public class FileOrganizationNode {
	private String name;
	private Integer value;
	private String nodeType;
	private List<FileOrganizationNode> children;

getTreeNode方法:

    // 递归获取子node
    getTreeNode:function(treeSource){
    	if(treeSource){
    		var childNode = new Array();
			$.each(treeSource, function(i, item){
				childNode.push({name:item.name, value:item.value, children:$biosMain.getTreeNode(item.children), nodeType:item.nodeType, 
					itemStyle: {normal: {color: $biosMain.getItemStyle(item.nodeType)}}});
			});
			return childNode;		// 通过return childNode串联递归
    	}
    	return null;
    },
    
    getItemStyle:function(nodeType){
    	if ("person" == nodeType) {
    		return '#cc9999';
    	} else if ("dept" == nodeType) {
    		return '#cc3333';
    	}
    	return '';
    }

treeNode内容:

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值