From ae5cd9eced2f2a96bd9b4ed499ff4027764aab76 Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Fri, 28 Jul 2023 22:27:20 +0900 Subject: [PATCH] fixed bug to get parent indexes. --- src/database/lib/IndexUtil.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/database/lib/IndexUtil.ts b/src/database/lib/IndexUtil.ts index b34205e..7b8aeb0 100644 --- a/src/database/lib/IndexUtil.ts +++ b/src/database/lib/IndexUtil.ts @@ -148,20 +148,20 @@ class IndexUtil { } getParents(type: BrainAtlasType, parentId: number, func: SearchCallbackFunc): void { - const parents: Index[] = []; - const loop = (parentId: number, func: SearchCallbackFunc) => { - if (parentId === INDEX_ID_ROOT) { - func(parents); - } else { - this.get(type, parentId, (parent) => { - if (parent != null) { - loop(parent.parentId, func); + this.registerIndexLoadCallback(type, (indexes) => { + const parents: Index[] = []; + const loop = (parentId: number) => { + if (parentId !== INDEX_ID_ROOT) { + const parent = indexes.findOne({ id: parentId }); + if (parent !== null) { + loop(parent.parentId); parents.push(parent); } - }); - } - }; - loop(parentId, func); + } + }; + loop(parentId); + func(parents); + }); } }