getTotalLevel static method
筛选项最多不超过三层,故直接写代码判断,本质为深度优先搜索。
Implementation
static int getTotalLevel(SelectionEntity entity) {
int level = 0;
SelectionEntity rootEntity = entity;
while (rootEntity.parent != null) {
rootEntity = rootEntity.parent!;
}
if (rootEntity.children.isNotEmpty) {
level = level > 1 ? level : 1;
for (SelectionEntity firstLevelEntity in rootEntity.children) {
if (firstLevelEntity.children.isNotEmpty) {
level = level > 2 ? level : 2;
for (SelectionEntity secondLevelEntity in firstLevelEntity.children) {
if (secondLevelEntity.children.isNotEmpty) {
level = 3;
break;
}
}
}
}
}
return level;
}