跳到主要内容

countAncestors

countAncestors 统计树结构实体的祖先数量,不返回实体本身。

四个树查询由插件包 @aiao/rxdb-plugin-tree 提供,库侧需先 rxdb.use(rxDBPluginTree)。见树结构拆包。

签名​

countAncestors(options: FindTreeOptions<T>): Observable<number>

统计语义​

  • 传 entityId:不包含当前节点,只统计祖先数量
  • level 的归一化规则与 findAncestors 一致
  • 根节点的祖先数量通常就是 0

基础用法​

import { firstValueFrom } from 'rxjs';

const count = await firstValueFrom(
Menu.countAncestors({
entityId: leaf.id
})
);

判断是否为根节点​

const isRoot = (await firstValueFrom(Menu.countAncestors({ entityId: node.id }))) === 0;

限制层级统计​

const parentOnly = await firstValueFrom(
Menu.countAncestors({
entityId: leaf.id,
level: 1
})
);

参考​