getTotalLevel static method

int getTotalLevel(
  1. TSelectionEntity entity
)

筛选项最多不超过三层,故直接写代码判断,本质为深度优先搜索。

Implementation

static int getTotalLevel(TSelectionEntity entity) {
int level = 0;
TSelectionEntity rootEntity = entity;
while (rootEntity.parent != null) {
  rootEntity = rootEntity.parent!;
}

if (rootEntity.children.isNotEmpty) {
  level = level > 1 ? level : 1;
  for (TSelectionEntity firstLevelEntity in rootEntity.children) {
    if (firstLevelEntity.children.isNotEmpty) {
      level = level > 2 ? level : 2;
      for (TSelectionEntity secondLevelEntity
          in firstLevelEntity.children) {
        if (secondLevelEntity.children.isNotEmpty) {
          level = 3;
          break;
        }
      }
    }
  }
}
return level;
  }