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--;
}
}
}