`
LiYunpeng
  • 浏览: 958326 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

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

    博客分类:
  • Flex
阅读更多
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--;
				}
			}	
		}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics