ITeye博客

AS中,使用递归来计算 Tree的深度

LiYunpeng · 2010-11-01 13:41 · Flex · Web前端 · ActionScript · Markdown

AS中,使用递归来计算 Tree的深度

这是网上一位朋友提供的源代码,个人截取了这个方法内容作为学习笔记


private var _treeDataDesciptor:ITreeDataDescriptor = new DefaultDataDescriptor;

private function calculateDepth(data:ICollectionView):void{
			for(var cursor:IViewCursor = data.createCursor(); !cursor.afterLast; cursor.moveNext()){
				if(_treeDataDesciptor.isBranch(cursor.current, data) 
					&&  _treeDataDesciptor.getChildren(cursor.current, data).length != 0){
					
					_currentDepth++;
					
					if(_currentDepth > _depth){
						_depth = _currentDepth;
					}
					
					var __tmp:ICollectionView = _treeDataDesciptor.getChildren(cursor.current, data);
					calculateDepth(__tmp);
					
					_currentDepth--;
				}
			}	
		}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。