读书人

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

发布时间: 2012-10-26 10:30:59 作者: rapoo

AS中,使用递归来计算 Tree的深度
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--;}}}

读书人网 >Web前端

热点推荐