@cn-ui/core
Version:
The @cn-ui/core is a collection of UI components and utilities for building modern web applications with SolidJS.
21 lines (20 loc) • 491 B
text/typescript
export const flatLoop = <
T extends {
level?: number;
options?: T;
}[],
>(
rows: T,
collection: T,
deep = 0,
) => {
if (deep > 3) console.warn("GroupList | find an option deeper then 3 layers");
rows.forEach((i) => {
const data = { ...i, level: deep };
collection.push(data);
if ("options" in data) {
flatLoop((data as { options: T }).options, collection, deep + 1);
}
});
return collection;
};