fixed bug to get parent indexes.

This commit is contained in:
Yoshihiro OKUMURA 2023-07-28 22:27:20 +09:00
parent 8f37b9c537
commit ae5cd9eced
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2

View File

@ -148,20 +148,20 @@ class IndexUtil {
} }
getParents(type: BrainAtlasType, parentId: number, func: SearchCallbackFunc): void { getParents(type: BrainAtlasType, parentId: number, func: SearchCallbackFunc): void {
const parents: Index[] = []; this.registerIndexLoadCallback(type, (indexes) => {
const loop = (parentId: number, func: SearchCallbackFunc) => { const parents: Index[] = [];
if (parentId === INDEX_ID_ROOT) { const loop = (parentId: number) => {
func(parents); if (parentId !== INDEX_ID_ROOT) {
} else { const parent = indexes.findOne({ id: parentId });
this.get(type, parentId, (parent) => { if (parent !== null) {
if (parent != null) { loop(parent.parentId);
loop(parent.parentId, func);
parents.push(parent); parents.push(parent);
} }
}); }
} };
}; loop(parentId);
loop(parentId, func); func(parents);
});
} }
} }